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

Sign in to report

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) without mine. Each calls _reader (:741-748): namespace.full_name (a query), then access.membership, which resolves the project by name again (namespace.resolve, 2-3 queries) and selects the membership (and builds a ProxyGo for a proxy). The list query itself already joined the caller's membership (:778-784). restricted.served then reads every membership of each project.
  • Proposal: select the membership row with the project, build Membership once per row and pass it as mine to _stored and _serve_restricted, as _view does 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 runs inbox.addressed_to per 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_requests takes the Membership.
  • 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 runs avatars.may_read (avatars.py:525ff: instance admin, the projects of the owner), then avatars.urls, else avatars.is_public (avatars.py:335-360: the human row and public_people.served, or for an agent its owner row and listed_agents).
  • Proposal: a set form, for example avatars.readable(conn, caller, ids) -> set[str] with one membership query, then one avatars.urls and one public_urls call 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, each handles.aliases plus a handle select. _handles_of repeats namespace.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=) calls admits_name per profile, which resolves the same allowed_in name once per profile.
  • Proposal: collect the owner ids of the project and its aliases, call handles.aliases once for all of them and read their current handles in one query; in list_agents, resolve allowed_in once and call admits per profile.
  • Effort: S. Risk: none (test_allowed_projects).

Covered elsewhere

  • GET …/overview (latest_reports loads every reported card of the project; request_counts runs 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.