Skip to content

Avoid redundant queries when recalculating payment totals#6494

Open
ikraamg wants to merge 1 commit into
solidusio:mainfrom
ikraamg:perf/payment-total-use-loaded-payments
Open

Avoid redundant queries when recalculating payment totals#6494
ikraamg wants to merge 1 commit into
solidusio:mainfrom
ikraamg:perf/payment-total-use-loaded-payments

Conversation

@ikraamg

@ikraamg ikraamg commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Recalculating the payment total preloaded each payment's refunds with includes(:refunds) but then summed them with refunds.sum(:amount), which issues a separate query per payment instead of using the records already loaded.

  • sums the preloaded refunds in memory
  • refund queries stay at the single preload regardless of how many payments the order has

Comment thread core/spec/models/spree/order_updater_spec.rb
Comment thread core/spec/models/spree/order_updater_spec.rb
Comment thread core/spec/models/spree/order_updater_spec.rb
@github-actions github-actions Bot added the changelog:solidus_core Changes to the solidus_core 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.68%. Comparing base (8d781ac) to head (2d3081b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6494   +/-   ##
=======================================
  Coverage   89.68%   89.68%           
=======================================
  Files         993      993           
  Lines       20863    20863           
=======================================
  Hits        18712    18712           
  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.

Recalculating the payment total preloaded each payment's refunds but
then summed them with a column-level sum, issuing one extra query per
payment. Summing the already-loaded refunds keeps it to the single
preload.
@ikraamg ikraamg force-pushed the perf/payment-total-use-loaded-payments branch from 74f3f54 to 2d3081b Compare June 26, 2026 03:27
@ikraamg ikraamg marked this pull request as ready for review June 26, 2026 06:34
@ikraamg ikraamg requested a review from a team as a code owner June 26, 2026 06:34

@tvdeyen tvdeyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please ignore the hound comments. We already removed the webhook and reached out to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_core Changes to the solidus_core gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants