Reduce queries while generating orders #158
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes proposed in this Pull Request:
This reduces the number of queries that run during order generation by storing lists of customer and product IDs that are used in orders in a runtime cache, rather than making new queries for those IDs every time an order is generated. The runtime cache does get refreshed every 100 orders, so that a greater variety of customers and products will be used during large batches.
More crucially, this seems to mitigate the memory leak described in #152. With these changes, I was able to run the command mentioned in the issue to generate 50k orders and never encountered an out of memory error. (It still took forever, I just let it run overnight 😄)
Note that this also changes the behavior of the Orders generator so that it no longer generates new customer accounts. It will only use existing accounts or generate data for "guest" orders. Customers can be generated separately using the Customers generator before running the Orders generator.
Builds off of #119
Towards #152
How to test the changes in this Pull Request:
Changelog entry