oliver-zehentleitner / maity
clean-up: G4 slow paths: GET /projects resolves the membership twice per project, GET /me counts requests per project, contacts and people pages check avatars per row
tsk-m49x61yesmb6 Open
From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G4 Members, projects, joins and briefing), read at 9dfd4b65. Line numbers are at that SHA. Paths are under hub/src/maity_hub/.
Slow paths on read routes. Each item: add a statement-count test with 1 and 5 rows before the change.
1. GET /projects resolves the caller's membership twice per project
- Kind: slow path (N+1).
- Files: routes/projects.py:774-812 (
list_projects). Per project row it calls_stored(conn, r, request)(:804, then :696-697) and_serve_restricted(conn, r, request, ...)(:793, then :761-763) withoutmine. Each calls_reader(:741-748):namespace.full_name(a query), thenaccess.membership, which resolves the project by name again (namespace.resolve, 2-3 queries) and selects the membership (and builds aProxyGofor a proxy). The list query itself already joined the caller's membership (:778-784).restricted.servedthen reads every membership of each project. - Proposal: select the membership row with the project, build
Membershiponce per row and pass it asmineto_storedand_serve_restricted, as_viewdoes since tsk-6srccd2r1h62. - Effort: S-M. Risk: low (who sees the storage figures and the restricted setting must not change; test_restricted_set covers the setting).
2. GET /me and GET /bootstrap count open requests per project
- Kind: slow path (N+1 over memberships).
- Files: routes/me.py:216 calls
open_requests(:241-258) per membership. Each call reads the membership and the project again (both were just read by_human_projects:189-203), loads every open non-personal request of the project, and runsinbox.addressed_toper row. notifications/listing.py:40 calls it per membership too. - Proposal: one query of the open non-personal requests of all the human's projects, grouped by project in Python, with the membership and project rows already read;
open_requeststakes theMembership. - Effort: S. Risk: low (the count must stay
GET …/requests?to=me; test_me).
3. The contact lists and the people page check each avatar one by one
- Kind: slow path (N+1).
- Files: routes/people.py:96-103 (
_avatar) per row of_contact_list(:295-303, up to 200 rows), per organisation member (:211-219) and per listed agent in_agents(:154-156). Per id it runsavatars.may_read(avatars.py:525ff: instance admin, the projects of the owner), thenavatars.urls, elseavatars.is_public(avatars.py:335-360: the human row andpublic_people.served, or for an agent its owner row andlisted_agents). - Proposal: a set form, for example
avatars.readable(conn, caller, ids) -> set[str]with one membership query, then oneavatars.urlsand onepublic_urlscall for the page. - Effort: S-M. Risk: low to medium (who may read a picture, §6.10; test_contacts, test_people, test_avatars).
4. allowed_projects reads two statements per project alias
- Kind: slow path, duplication.
- Files: allowed_projects.py:54-69 (
names_of) calls_handles_of(:41-51) for the owner and once per alias, eachhandles.aliasesplus a handle select._handles_ofrepeatsnamespace.current_handle(namespace.py:175-179). It runs on every join, exchange and pickup (admits), and routes/agents.py:138-143 (GET /agents?allowed_in=) callsadmits_nameper profile, which resolves the sameallowed_inname once per profile. - Proposal: collect the owner ids of the project and its aliases, call
handles.aliasesonce for all of them and read their current handles in one query; inlist_agents, resolveallowed_inonce and calladmitsper profile. - Effort: S. Risk: none (test_allowed_projects).
Covered elsewhere
- GET …/overview (
latest_reportsloads every reported card of the project;request_countsruns the request filter in Python): tsk-ybc2ma72dzvq item 3. - The resume packet's request block: tsk-tnmcav72bhg9 item 3.
- Searched: list_projects, open_requests, _contact_list, may_read, admits_name.
Effort sum: 2 S-M + 2S, about 6 points.