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

Sign in to report

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:100 and elsewhere.
  • Proposal (no behaviour change):
  • move ts to clock (see the time-format card filed with this one);
  • move principal_id(s) and routing_boss to a small principals.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 to forge.kind_of; its outside caller is routes/projects.py:448.
  • watching (1114-1118) only forwards to card_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 second names to project_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 passed revoke_due_at as revoked (§15.3); runner_revoke.py:135 applies 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:628 and :1321 build task_view(conn, parent, fg) only to read ["children"] for the parent's task_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 at views.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:23 imports views._without_reason and calls it at :121.
  • routes/bootstrap.py:27-35 imports four private helpers from deps: _confine_pending, _confine_runner, _end_session and _refuse_other_project. Its part() (bootstrap.py:74-103) re-implements the refusal order of deps._resolve and the middleware.
  • Its 503 maintenance body (bootstrap.py:76-81) is a copy of middleware.py:348-353.
  • Proposal:
  • make without_reason public;
  • give deps one public refusals_for(conn, caller, method, path, project) that both deps._resolve and 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_of and views.py:1276-1282 (owners in _standing_of): tsk-9tj3p6ca30m6.
  • views.py:170-176 owner_handles and the inline copy in confirmed_by_of (views.py:201-204): tsk-ee3z4rakddq9.

Effort sum: L+S+S+S+M = 11 points.