Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single flush per "user-land" create #37

Closed
Tracked by #110
kbond opened this issue Sep 10, 2020 · 1 comment · Fixed by #84
Closed
Tracked by #110

Single flush per "user-land" create #37

kbond opened this issue Sep 10, 2020 · 1 comment · Fixed by #84
Labels
enhancement New feature or request
Milestone

Comments

@kbond
Copy link
Member

kbond commented Sep 10, 2020

Currently, the following code calls $em->flush() twice. First, when creating the nested CategoryFactory and a second time after persisting the PostFactory.

PostFactory::new()->create([
    'category' => CategoryFactory::new(),
]);

It would be better if the nested CategoryFactory was just persisted, then after the PostFactory is persisted, a single flush occurs capturing all changes.

@kbond kbond added the enhancement New feature or request label Sep 10, 2020
@kbond kbond added this to the 2.0 milestone Sep 28, 2020
@kbond
Copy link
Member Author

kbond commented Nov 9, 2020

@voltel has noted significant performance issues when creating 1000's of factories. @wouterj, might be something to consider with #76?

One solution I thought of is to create a static Factory::delayFlush() method that accepts a callback where you create your factories/stories:

Factory::delayFlush(function() {
    PostFactory::new()->createMany(10000);

    // etc...
});

Before the callback is executed, flushing is disabled globally (new concept). Any factories created within the callback are just persisted. After the callback is executed, run flush and re-enable flushing globally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant