Every page: two EXISTS queries ask whether the instance has accounts and whether the person has groups #1115
Labels
No labels
accessibility
authentication
breaking change
bug
documentation
enhancement
interface
internationalisation
observability
performance
security
tier
1
tier
2
tier
3
tier/4
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Postulo/postulo#1115
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What exists today
src/postulo/core/context_processors.py:107putssite.signup_open_now()in every page's context.core/site.py:300-307returnsregistration_open() or is_empty(), andis_empty()(:295-297) runsget_user_model().objects.exists(). When sign-up is closed, which is the usual state, every full page runsSELECT 1 FROM accounts_user LIMIT 1.src/postulo/templates/base.html:241writes{% if user.groups.exists %}in the account menu, which every full page draws for a signed-in person:SELECT 1 FROM auth_group INNER JOIN accounts_user_groups ... LIMIT 1.Both seen in the second GET of
core:homeunder the test settings (probeaudit/m_scripts/test_probe_queries.py): 20 queries, these two among them. Each is a cheap indexed lookup, so the win is in query count, not in time.What would change
is_empty(): once an instance has an account it almost never goes back to none. Remember a false answer in the process and forget it onpost_deleteof the user model (a receiver that clears the flag), so the rare "every account deleted" case still opens sign-up as today.user.groups.exists: compute it once in the context processor, only for an authenticated user, and only where the account menu is drawn; or as ahas_groupsattribute set once on the request. The menu item and its markup do not change.What it saves or protects
small: two of the 20 queries on the home page (measured), on every full page for everyone signed in
Accessibility
none
Decisions
Found by the efficiency and reliability audit of 2026-10-30 (finding Q4; index postulo/postulo#1108). Checked against
mainatdaee30b15(2026-10-30).