Skip to content

Admin loads associations on-demand, not immediately#928

Open
rgalanakis wants to merge 25 commits into
mainfrom
efficient-admin
Open

Admin loads associations on-demand, not immediately#928
rgalanakis wants to merge 25 commits into
mainfrom
efficient-admin

Conversation

@rgalanakis
Copy link
Copy Markdown
Member

@rgalanakis rgalanakis commented May 24, 2026

Admin entities expose lists, rather than eagerly loading all data.

We had associations with thousands of rows; this would blow out memory in production very quickly.
Instead, just return the first handful of items as collections, and then the 'related' list can page in additional results.

Admin is much snappier and uses much less memory. It did require a pretty massive change, exposing resources as proper collections rather than just array properties.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

❌ Patch coverage is 99.82964% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.79%. Comparing base (17123bd) to head (adc907b).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
spec/suma/api/behaviors.rb 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #928      +/-   ##
==========================================
- Coverage   99.82%   99.79%   -0.04%     
==========================================
  Files         750      755       +5     
  Lines       37253    37818     +565     
==========================================
+ Hits        37189    37740     +551     
- Misses         64       78      +14     

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

This was a beast, as these things often go,
but we need this for future pagination,
and we need eager loading or things break
for some reason due to tactical eager loading
and large association warning.
Add two plugins to help with association loading performance.

- large association warning: warn when associations over a certain size are loaded. Prevents unexpectedly blowing out memory.
- efficient each: Allows 1) reusing a loaded association array, 2) streaming a not-loaded association from the database, and 3) storing a streamed association into the array if it's just one page. Move each_cursor_page to this plugin.
Loading combined_book_transactions could be very big.
Use efficient_each to optimizing loading.
Reconfiguring the model replaced the DB which caused
spec corruption.
* efficient-admin-prep:
  Fix issues with database corruption
  Ledger: Use efficient_each
  Add useDebugEffect to debug things on load.
  Add association loading performance plugins
  Vendor: Add discounted_rates association
  Card: Add originated_funding_transactions dataset
  Turn combined_notes into an association
Reconfiguring the model replaced the DB which caused
spec corruption.
* efficient-admin-prep:
  Fix issues with database corruption
* main:
  Fix issues with database corruption
  Ledger: Use efficient_each
  Add useDebugEffect to debug things on load.
  Add association loading performance plugins
  Vendor: Add discounted_rates association
  Card: Add originated_funding_transactions dataset
  Turn combined_notes into an association
@rgalanakis rgalanakis marked this pull request as ready for review May 25, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant