Skip to content

Conversation

@mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Nov 21, 2025

Summary

This PR does four things:

  1. Fix the DistributedAmountsHandler to not require line items IDs, so it can work with in-memory line items
  2. Fix the taxon condition to work with in-memory line items (by not executing an ActiveRecord query on line items).
  3. For the taxon family of conditions, reduces the number of calls to the database to find the preconfigured taxon IDs and children needed to check against to one per condition per promotion run.
  4. For the option value condition, do not use pluck and rather take advantage of loaded option values.

The taxon condition is likely one of our most-used conditions, so it makes sense to spend a bit of time here making sure it's not too slow.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@github-actions github-actions bot added the changelog:solidus_promotions Changes to the solidus_promotions gem label Nov 21, 2025
@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.45%. Comparing base (fc3adf7) to head (19592f0).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
...s/solidus_promotions/conditions/taxon_condition.rb 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6383      +/-   ##
==========================================
- Coverage   89.45%   89.45%   -0.01%     
==========================================
  Files         974      974              
  Lines       20322    20330       +8     
==========================================
+ Hits        18179    18186       +7     
- Misses       2143     2144       +1     

☔ View full report in Codecov by Sentry.
📢 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.

In-memory line items don't have an ID, but we can just use the line item
itself as the key.
@mamhoff mamhoff force-pushed the in-memory-conditions branch from bbb2417 to 394e83d Compare November 22, 2025 17:00
This refactors the taxon conditions to rely on in-memory properties of
line items rather than on the current database state of the order. The
database state of the conditions is still necessary - we're not
changing conditions while calculating promotions.

The change to the order condition will result in a lot of queries to
line item product classifications - but since it's an order level
condition, that is only going to happen once. For line item level
condition, we're actually removing an n+1 here, because we're
instacaching the list of taxons and descendants on the condition
instance.
@mamhoff mamhoff force-pushed the in-memory-conditions branch from 394e83d to 309d917 Compare November 23, 2025 11:55
Promotion calculation should be fast, so let's optimize the slowest
parts.
If we don't use pluck, we can preload.
@mamhoff mamhoff force-pushed the in-memory-conditions branch from 309d917 to 19592f0 Compare November 23, 2025 12:06
@mamhoff mamhoff changed the title In memory conditions Allow promotion conditions to work with in-memory line items, improve performance Nov 23, 2025
@mamhoff mamhoff marked this pull request as ready for review November 23, 2025 12:15
@mamhoff mamhoff requested a review from a team as a code owner November 23, 2025 12:15
@tvdeyen tvdeyen added backport-v4.6 Backport this pull-request to v4.6 and removed backport-v4.6 Backport this pull-request to v4.6 labels Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_promotions Changes to the solidus_promotions gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants