Skip to content

Eager load associations in admin and API collection endpoints#6504

Open
ikraamg wants to merge 1 commit into
solidusio:mainfrom
ikraamg:fix-collection-n-plus-one-queries
Open

Eager load associations in admin and API collection endpoints#6504
ikraamg wants to merge 1 commit into
solidusio:mainfrom
ikraamg:fix-collection-n-plus-one-queries

Conversation

@ikraamg

@ikraamg ikraamg commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

A few admin and API list endpoints render per-row associations that were not eager loaded, so the query count grew with the number of rows. This eager loads what each view already renders.

  • solidus_admin products index: the stock column calls total_on_hand, which loaded each variant's stock items and their stock location per row
  • solidus_admin stock items index: each row loaded its variant, the variant's product, images, option values, and the stock location
  • API stock movements index: each movement loaded its stock item and the variant data the listing renders (product, prices, stock, images, option values)
  • API users index: each user loaded its billing and shipping address
  • admin order payments list: each payment loaded its payment method

Each fix is a controller-level includes. The specs assert the relevant table is loaded in a single batched query as the number of rows grows.

Several index and show endpoints rendered per-row associations that were
not eager loaded, so the query count grew with the number of rows:

- solidus_admin products index: the stock column reads total_on_hand,
  loading each variant's stock items and their stock location
- solidus_admin stock items index: each row loads its variant, the
  variant's product, images, option values, and the stock location
- API stock movements index: each movement renders its stock item and
  the variant graph the listing shows (product, prices, stock, images,
  option values)
- API users index: each user renders its billing and shipping address
- admin order payments list: each payment renders its payment method

Eager load the associations each view renders so the queries are batched.
@github-actions github-actions Bot added changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_admin labels 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 (342a3dc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6504   +/-   ##
=======================================
  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 09:44
@ikraamg ikraamg requested a review from a team as a code owner June 26, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_admin changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant