-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Performance improvements on package generation #550
Performance improvements on package generation #550
Conversation
@dfmedeiros this looks fantastic, really appreciated. I'm slammed by BlackFriday/Monday stuff but will pull it down and give it a run early next week. On first glance everything looks great though. |
Looks good to me. 👍 I bet we could go further here and select the stock items grouped by stock_location, and skip the N+1 on line 59, but this is an excellent step towards that. |
@cbrunsdon - Thanks for the feedback! @jhawthorn - Yep, good catch! But I didn't get it correctly, what do you mean by My plan is to select the correct stock items by def requested_stock_items
Spree::StockItem.where(variant_id: unnalocated_variant_ids).includes(:variant, :stock_location)
end
def build_packages(packages = Array.new)
requested_stock_items.each do |stock_item|
units_for_location = unallocated_inventory_units.select { |unit| unit.variant.eql?(stock_item.variant) }
packer = build_packer(stock_item.stock_location, units_for_location)
packages += packer.packages
end
packages
end What do you think about this approach? Do you recommend doing something else? |
👍 on this and on @jhawthorn's suggestion |
@jhawthorn - Forget about my last comment, it doesn't work as I expected, but, I didn't get your last comment to select stock items grouped by stock location. I don't see how this would do any benefit for the queries on line 59. |
where(spree_stock_items: { variant_id: unnalocated_variant_ids }).uniq | ||
end | ||
|
||
def unnalocated_variant_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unallocated*
Solid 👍 |
@dfmedeiros no worries. We can worry about future improvements after addressing this. I think this is good to merge pending the spelling fix. |
Right now, when Solidus tries to create the packages on Coordinator, it iterates over each one of the active stock locations and skip those without the requested variants in stock. Let's suppose we have 100 different stock locations (which is my case) and the current user has 5 items on his cart. Once it tries to create the packages it triggers 500 different queries to the database. Here I try to address this issue, iterating over just the stock locations with the requested variants in stock.
1d24646
to
3832534
Compare
@jhawthorn - Great, just fixed the typo. Thanks. |
…lding_packages Performance improvements on package generation
Thank you @dfmedeiros |
Right now, when Solidus tries to create the packages on
Coordinator
, it iterates over each one of the active stock locations and skip those without the requested variants in stock.Let's suppose we have 100 different stock locations (which is my case) and the current user has 5 items on his cart. Once it tries to create the packages it triggers 500 different queries to the database.
Here I try to address this issue, iterating over just the stock locations with the requested variants in stock.