Skip to content

Improve Solidus Admin Orders Loading Performance#6440

Merged
tvdeyen merged 3 commits intosolidusio:mainfrom
blish:solidus-admin-orders-loading-performance
Apr 17, 2026
Merged

Improve Solidus Admin Orders Loading Performance#6440
tvdeyen merged 3 commits intosolidusio:mainfrom
blish:solidus-admin-orders-loading-performance

Conversation

@sascha-karnatz
Copy link
Copy Markdown
Contributor

Summary

On data sets with a few million rows the orders view is becoming very slow. It takes around 72 seconds to load the completed scope with 8 million orders in the database.
This change is improving the loading performance slightly to around 500ms*. It also removes one N+1s in the order index view.

*the geared_pagination gem is causing some delays because they are not unscoping the order on the count queries and that is increasing the loading time. We have to consider to move to kaminari instead.

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.

Distinct is only necessary on left joins with a lot of duplicated rows. On a normal select without any joins it is slowing down the respond time, because the database has to run additional aggregation steps.
Disable the distinct for the order controller. This reduces the query time for 8M orders from 72sec to 18sec.
The created_at column does not have an index and there will be a tmp table created to order the result set. This will cause a delay on huge data sets.
Move the order statement into the search scopes to sort each scope individually. It is also faster to sort only one column instead of two. Only the scopes that are filtering already completed orders will sort by completed_at.
This change reduced the loading time of 8M orders from 18sec to 836ms.
There was a N+1 query in order index view. For each row the quantity of the line items was fetched. It is now included and reduces the amount of SQL queries.
This change reduced the loading time of 8M orders from 836ms to 520ms.
@sascha-karnatz sascha-karnatz force-pushed the solidus-admin-orders-loading-performance branch from 90c8457 to 389218d Compare April 16, 2026 15:11
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.66%. Comparing base (e6705cb) to head (389218d).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6440   +/-   ##
=======================================
  Coverage   89.66%   89.66%           
=======================================
  Files         990      990           
  Lines       20792    20792           
=======================================
  Hits        18644    18644           
  Misses       2148     2148           

☔ 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.

Copy link
Copy Markdown
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Nice! Thanks

Copy link
Copy Markdown
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

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

Great work. Much needed.

@tvdeyen tvdeyen merged commit 852cb8e into solidusio:main Apr 17, 2026
39 checks passed
@tvdeyen tvdeyen deleted the solidus-admin-orders-loading-performance branch April 17, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants