Preload line item variants and products in the promotions order adjuster - #6525
Open
ikraamg wants to merge 1 commit into
Open
Preload line item variants and products in the promotions order adjuster#6525ikraamg wants to merge 1 commit into
ikraamg wants to merge 1 commit into
Conversation
Necessary because DiscountOrder reads `line_item.variant.product` for every line item to check whether the product is promotionable, and nothing preloaded that chain. Line items hold distinct variants, so the query cache cannot collapse the lookups: an order paid one variant query per line item on every recalculation, and building a cart performs one recalculation per item added. This runs whether or not any promotion exists, so a store that installs the gem and configures nothing still pays it. On a freshly loaded twenty-five item cart with no promotions at all, those lookups were thirty-one of the recalculation's thirty-eight queries. Shipments have no variant association, so this cannot be folded into the existing adjustments preload and runs as its own pass over line items. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6525 +/- ##
==========================================
- Coverage 95.07% 92.38% -2.70%
==========================================
Files 460 42 -418
Lines 7924 788 -7136
==========================================
- Hits 7534 728 -6806
+ Misses 390 60 -330 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SolidusPromotions::OrderAdjusterpreloads each line item's adjustments, butDiscountOrder#adjust_line_itemsthen readsline_item.variant.productfor every line item and nothing preloaded that chain. Line items hold distinct variants, so the query cache cannot collapse the lookups.adjust_line_itemsruns for every lane before its benefits are consulted, so a store that installs SolidusPromotions and configures no promotions at all still pays one variant and one product lookup per line item on every recalculation.{variant: :product}over the line items, as its own pass since shipments have no variantRecalculating a five line item order drops from 31 to 25 queries, and a ten line item order from 38 to 25. The saving appears when the order is loaded fresh from the database, which is the ordinary storefront path of loading a cart and recalculating it.
Both specs were confirmed to fail without the fix, reporting "expected 1 query, but 3 were made" on a three line item order.