Skip to content

Preload variants when checking order promotionability to avoid an N+1#6499

Open
ikraamg wants to merge 1 commit into
solidusio:mainfrom
ikraamg:perf/promotion-eligibility-preload-variant
Open

Preload variants when checking order promotionability to avoid an N+1#6499
ikraamg wants to merge 1 commit into
solidusio:mainfrom
ikraamg:perf/promotion-eligibility-preload-variant

Conversation

@ikraamg

@ikraamg ikraamg commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Evaluating a promotion's eligibility checks whether the order contains a non-promotionable product, reading each line item's variant and product with a separate query per line item. This runs every time a promotion is evaluated, including on order recalculation when promotions are present.

  • preloads each line item's variant and product before the promotionable check
  • variant and product loads stay constant regardless of order size
  • adds a spec asserting line item variants load in a single query

Checking whether an order contains a non-promotionable product loaded
each line item's variant and product with a query per line item. This
runs every time a promotion's eligibility is evaluated.

Preloading the variant and product for all line items keeps that load
constant regardless of how many items the order has.
@github-actions github-actions Bot added the changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem label Jun 26, 2026
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.69%. Comparing base (8d781ac) to head (1003344).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6499   +/-   ##
=======================================
  Coverage   89.68%   89.69%           
=======================================
  Files         993      993           
  Lines       20863    20864    +1     
=======================================
+ Hits        18712    18713    +1     
  Misses       2151     2151           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ikraamg ikraamg marked this pull request as ready for review June 26, 2026 06:35
@ikraamg ikraamg requested a review from a team as a code owner June 26, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant