Skip to content

Increase element window loading performance#3658

Open
tvdeyen wants to merge 4 commits intomainfrom
performance/admin-element-index
Open

Increase element window loading performance#3658
tvdeyen wants to merge 4 commits intomainfrom
performance/admin-element-index

Conversation

@tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Feb 6, 2026

What is this pull request for?

Introduce a new service that preloads element trees efficiently,
eliminating N+1 queries for nested elements at any depth.

Add alchemy_element_preloads hook to RelatableResource concern.
Batch load picture thumbnails in Picture

This eliminates N+1 queries when loading picture thumbnails in the
element editor. The generic preloading mechanism allows any related
object to define custom preloading by implementing alchemy_element_preloads.

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@tvdeyen tvdeyen added this to the 8.1 milestone Feb 6, 2026
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.47%. Comparing base (5a860a2) to head (18b797f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3658      +/-   ##
==========================================
+ Coverage   97.45%   97.47%   +0.01%     
==========================================
  Files         316      317       +1     
  Lines        8370     8428      +58     
==========================================
+ Hits         8157     8215      +58     
  Misses        213      213              

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

@tvdeyen tvdeyen force-pushed the performance/admin-element-index branch 4 times, most recently from 4c6f520 to 476cc5d Compare February 9, 2026 09:40
@tvdeyen tvdeyen removed this from the 8.1 milestone Feb 9, 2026
@tvdeyen tvdeyen force-pushed the performance/admin-element-index branch from 476cc5d to 07eec5a Compare February 9, 2026 15:01
@tvdeyen tvdeyen added the performance Performance improvement label Feb 9, 2026
@tvdeyen tvdeyen added this to the 8.2 milestone Feb 18, 2026
@tvdeyen tvdeyen force-pushed the performance/admin-element-index branch 7 times, most recently from 2e190b5 to e300bf9 Compare March 2, 2026 10:21
@tvdeyen tvdeyen force-pushed the performance/admin-element-index branch from e300bf9 to 53d38f1 Compare March 4, 2026 14:31
@tvdeyen tvdeyen marked this pull request as ready for review March 4, 2026 14:31
@tvdeyen tvdeyen requested a review from a team as a code owner March 4, 2026 14:31
@tvdeyen tvdeyen force-pushed the performance/admin-element-index branch 3 times, most recently from 48b8f58 to 2e9c286 Compare March 4, 2026 17:30
@tvdeyen tvdeyen force-pushed the performance/admin-element-index branch 5 times, most recently from 80cafb5 to 31c86c4 Compare March 12, 2026 14:35
Introduce a new service that preloads element trees efficiently,
eliminating N+1 queries for nested elements at any depth.

Add alchemy_element_preloads hook to RelatableResource concern.
This can be used for eager loading ie. picture thumbnails.
tvdeyen added 3 commits March 12, 2026 16:39
Replace recursive N+1 query pattern with single-query
When all_nested_elements is already loaded (via ElementTreePreloader),
use the preloaded data instead of querying the database. This avoids
N+1 queries when re-initializing TinyMCE editors in the element editor.
When rendering element editors, each picture's thumbnail_url was
triggering an individual query to find the thumb by signature. Now
thumbs are preloaded in batch via the ElementTreePreloader's call
to Picture.alchemy_element_preloads.
@tvdeyen tvdeyen force-pushed the performance/admin-element-index branch from 31c86c4 to 18b797f Compare March 12, 2026 15:40
Copy link
Contributor

@sascha-karnatz sascha-karnatz left a comment

Choose a reason for hiding this comment

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

LGTM. I only would like to know why we need DBQueryMatchers?

end
end

DBQueryMatchers.configure do |config|
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this gem?

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Labels

performance Performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants