Skip to content

fix(tier): lazy-load Tier.users instead of eager-loading it - #294

Merged
igorbenav merged 3 commits into
benavlabs:mainfrom
nicolasgutierrezdev:fix/tier-model-lazy-select
Sep 13, 2026
Merged

igorbenav merged 3 commits into
benavlabs:mainfrom
nicolasgutierrezdev:fix/tier-model-lazy-select

Conversation

@nicolasgutierrezdev

Copy link
Copy Markdown
Contributor

Summary

Tier.users used lazy="selectin", so every Tier load pulled in all of its users. Since most users sit in the default tier, SQLAdmin's tier pages loaded roughly the whole user table. This switches it to lazy="select", the same fix as fastroai-template#88. No migration needed.

Impact (3,000 users)

Before After
Load 3 tiers 3,003 objects 3
Load 1 tier 1,001 objects 1

User loads are unaffected: User.tier stays selectin.

SQLAdmin

  • Tier list/export: no longer loads users (users isn't in column_list).
  • Tier detail/edit: works, no MissingGreenlcolumn by default, so SQLAdmin explicitlyselectinload`s it when you open a tier. Excluding it can be a follow-up.

Changes

  • src/modules/tier/models.py: Tier.userslazy="select"
  • tests/unit/modules/tier/test_models.py: regression test locking lazy == "select"
  • Docs (database/models.md, admin-panel/adding-models.md, development.md): note Tier.users as a deliberate
    exception to the "use selectin" guidance

@igorbenav

Copy link
Copy Markdown
Collaborator

SQLAdmin still loaded Tier.users on the other tier pages: it selectinloads every relationship in the form columns (the details page reuses that query), and the users form field lists every row of the user table. With 300 users in one tier, the number of users loaded was:

List page Details/edit page Create/edit form
Before this PR 300 300 300
lazy="select" only 0 300 300
Now 0 0 0

What I added:

  • TierAdmin sets form_excluded_columns = [Tier.users] and column_details_exclude_list = [Tier.users]. The exclude list replaces column_details_list = "__all__", since SQLAdmin doesn't accept both; the details page shows the same columns as before, minus users.
  • Tests that users stays out of the tier form and details page.
  • The admin docs note now says to keep large collections out of the form and details page too, not just column_list.

@igorbenav
igorbenav merged commit 1b186f0 into benavlabs:main Sep 13, 2026
3 checks passed
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.

2 participants