oliver-zehentleitner / maity
clean-up: core platform: views.py: split the grab bag, dead and thin helpers, the revoke-due rule twice, private reach-ins
tsk-mdjps8xhj7qv Open
From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G1 core platform), read at 9dfd4b65. Paths are under hub/src/maity_hub/.
1. Design: views.py (1518 lines) is three modules plus a box of shared helpers
- Files:
- Other modules import views.py for small helpers:
- ts: about 25 modules, for example attachments.py:31, auth/sessions.py:33, mail/smtp.py:30.
- principal_id / principal_ids: about 30, for example admin_agents.py:32, board/links.py:196.
- deleted / deleted_person: notifications/items.py:21, routes/requests.py:54.
- views.py itself reads moderation, instances, bridges, briefings, listening, environment, person_links, releases, board, card_watches, group_chats and restricted. The import cycle is broken with 20 function-local imports in views.py: 403, 530, 583, 610, 629, 654, 665, 673, 713, 1005, 1082, 1101, 1116, 1155-1157, 1249, 1319, 1363, 1461, 1482.
- The matching "views reads this module" comments are at
availability.py:266,board/links.py:196,takeovers.py:42,instance_counts.py:100and elsewhere. - Proposal (no behaviour change):
- move
tsto clock (see the time-format card filed with this one); - move
principal_id(s)androuting_bossto a smallprincipals.py; - move the deleted-account shaping (
deleted,deleted_person,shape_deleted) to its own module; - split the rest into member views, task views and event views.
- Effort: L (mechanical, many imports).
- Risk: low for behaviour, high for merge conflicts. Do it in one PR at a quiet time.
2. Debt: dead and thin helpers
- Files:
event_view(views.py:1219-1221) has no caller in hub/src or hub/tests.forge_of(239-240) only forwards toforge.kind_of; its outside caller isroutes/projects.py:448.watching(1114-1118) only forwards tocard_watches.watching._release(1077-1084) wraps one call.- In
member_views:
- names holds the agents' global names at 633, then the projects' full names at 652: two meanings in one function.
- subagent_writers = writers (663) is only an alias.
- from maity_hub import person_links runs again inside the loop at 713, after 673.
- Proposal: delete
event_view; inline the forwarders; rename the secondnamestoproject_names. - Effort: S
- Risk: none.
3. Duplication: the credential's revoke-due rule twice
- Files:
_credential_counts(views.py:945-947) and_revocation(1037-1046) both count a passedrevoke_due_atas revoked (§15.3);runner_revoke.py:135applies the rule in SQL. - Proposal: one
effective_revoked_at(row, now)beside the credential code, used by both views. - Effort: S
- Risk: low.
4. Slow path: a whole card view built for its children count
- Files:
routes/tasks.py:628and:1321buildtask_view(conn, parent, fg)only to read["children"]for the parent'stask_updated. That view runs about 10 statements: edges, children, members, signing, release tags, links, notes, holds and the deleted-account shape. - Proposal: a
children_of(conn, card_ids)built from the query atviews.py:1138-1143, used there and in_task_views. - Effort: S
- Risk: low.
5. Design: private helpers imported across modules
- Files:
routes/project_messages.py:23importsviews._without_reasonand calls it at:121.routes/bootstrap.py:27-35imports four private helpers from deps:_confine_pending,_confine_runner,_end_sessionand_refuse_other_project. Itspart()(bootstrap.py:74-103) re-implements the refusal order ofdeps._resolveand the middleware.- Its 503 maintenance body (
bootstrap.py:76-81) is a copy ofmiddleware.py:348-353. - Proposal:
- make
without_reasonpublic; - give deps one public
refusals_for(conn, caller, method, path, project)that bothdeps._resolveand bootstrap call; - add one
maintenance.refusal_body(found)for both 503s. - Effort: M
- Risk: medium. The bootstrap's per-part answers must still match the single routes; test_bootstrap covers them.
Order
- Items 2 and 3 first; they are small.
- Item 1 last, after the other G1 cards that touch views.py.
Covered elsewhere (instances, not filed again)
views.py:541-551_owners_ofandviews.py:1276-1282(owners in_standing_of): tsk-9tj3p6ca30m6.views.py:170-176owner_handlesand the inline copy inconfirmed_by_of(views.py:201-204): tsk-ee3z4rakddq9.
Effort sum: L+S+S+S+M = 11 points.