Improve Solidus Admin Orders Loading Performance#6440
Merged
tvdeyen merged 3 commits intosolidusio:mainfrom Apr 17, 2026
Merged
Improve Solidus Admin Orders Loading Performance#6440tvdeyen merged 3 commits intosolidusio:mainfrom
tvdeyen merged 3 commits intosolidusio:mainfrom
Conversation
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.
90c8457 to
389218d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 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.
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: