oliver-zehentleitner / maity

clean-up: G2 cards: one task_updated emitter, one parent-children announcement, one close, and the other copies around routes/tasks.py

Sign in to report

tsk-wfmyqaye48m7 Open

From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G2 Cards, tasks, releases and roles), read at 9dfd4b65. Paths are under hub/src/maity_hub/. Line numbers are at 9dfd4b65; check them against current main first.

Duplication around the card writes in routes/tasks.py (2261 lines), merged.py and routes/board.py. None of these items changes behaviour.

1. task_updated is built by hand 14 times (duplication)

  • Sites:
  • routes/tasks.py:595, :623, :1231, :1295, :1316, :1464, :1679, :2094, :2250
  • merged.py:164, :193
  • routes/board.py:107 (inside changed, 85-120)
  • outside this group: seats.py:168, jourfixe/redaction.py:140
  • What is wrong: each site writes the same dict (id, fields, the values, history, project_state), the same subject=("task", id) and almost always audience(conn, card). Two of them have already lost required keys (bug card filed at the same time). board.changed is already most of the helper.
  • Proposal: one emit_task_updated(conn, card, project_state, values, *, history=(), actor=None, signature=None, extra_audience=()) next to audience. It derives fields from values and drops body. All 14 sites use it. board.changed keeps only its updated_at write and the history.stamp.
  • Effort: M (many sites, each trivial). Risk: low. Payload shapes are pinned by tests, so run the card, release, takeover and moderation suites.

2. "Tell the parent its children changed" is written three times (duplication)

  • Sites: routes/tasks.py:613-634 (_touch_parents), routes/tasks.py:1308-1327 (inline in cancel_by_moderation), merged.py:179-203 (_touch_parent). The merged copy also counts the children itself (merged.py:186-189), which repeats views._task_views (views.py:1138-1143).
  • Proposal: one touch_parents(conn, project, parent_ids, actor, fg) that takes an Actor (not mine/caller), used by all three. The counts always come from task_view(...)["children"].
  • Effort: S. Risk: low.

3. The columns of a close are written twice (duplication)

  • Sites: routes/tasks.py:401-410 (_closing) and merged.py:206-220 (_close). Both set closed_at, clear status_before_block and blocked_by_request, and clear release_in_flight for a release. routes/tasks.py:2048 also sets closed_at again after _closing has set it.
  • Proposal: merged._close uses _closing (once it lives in a domain module, see the Order note on tsk-dwrtrhdgzezs). Drop the second closed_at in report.
  • Effort: S. Risk: low. The release part matters for the bug card on merged_closes filed at the same time; do them together.

4. lease_active and the lease-expiry test are built inline beside their helpers (duplication)

  • _lease_active(card) exists (routes/tasks.py:1526-1532), but release (1573-1579) and assign (1749-1755) build the same 409 by hand. The hand-built copies also drop the if card.lease_until else None guard.
  • _lease_expired(card) (1548-1549) is repeated inline in _already_claimed (1502).
  • Proposal: call the helpers.
  • Effort: S. Risk: none.

5. "The report as the agent sent it" is defined twice (duplication)

  • merged.py:41-44 (report_key: the report without observed and mismatch, hashed) and probe.py:535-537 (_core: the same filter). Both decide whether a report is still the one an observation belongs to.
  • Proposal: probe._core calls a shared merged.report_core (or the reverse), so the two cannot disagree when a probe-only field is added.
  • Effort: S. Risk: none.

6. Thin or inline copies of _project_card, and private names imported across route modules (design)

  • routes/board.py:75-76 (_card) only calls _project_card. routes/takeovers.py:85-89 writes the same select inline, although the module already imports from routes/tasks.
  • Four route modules import private names of routes/tasks.py: routes/board.py:39 (_locked, _project_card), routes/contract_text.py:14 (_project_card), routes/restricted.py:34 (_locked, _project_card), routes/takeovers.py:22 (_locked). tsk-dwrtrhdgzezs covers only non-route modules, so these are not on it.
  • Proposal: make them public (locked_membership, project_card) in access.py or the domain module that tsk-dwrtrhdgzezs step 2 creates, and delete board._card.
  • Effort: S. Risk: none.

7. audience() makes one query per party (slow path on every card event)

  • routes/tasks.py:282-303: principal_id runs once for each of up to five parties (creator, assignee, area owner, holder, extras), each a single-row select, plus cards.area_owner. It runs for every card event: create, PATCH (and once per mirrored partner in _touch_partners), claim, release, assign, move (once per re-ranked card, routes/tasks.py:1674-1690), report and the merge.
  • Proposal: one principal_ids(conn, [...]) call (views.py:339, the batch form that already exists).
  • Effort: S. Risk: none. The order of the tokens must stay the same, because tests compare audiences.

Order

  • tsk-dwrtrhdgzezs step 2 moves audience, CREATED, status_moved, _assigned_instance and cancel_by_moderation out of routes/tasks.py. Put the new helpers of items 1-3 and 6 in that same domain module. Either do this card after that move, or make the move part of item 1.
  • tsk-92tjmmcfvwm4 (items 1 and 2) edits the edge writes at routes/tasks.py:946-950 and 1141-1149; rebase rather than conflict.
  • tsk-p3a14j8p1rg9 already lists the inline project_closed at routes/tasks.py:562 and :1653, and routes/board.py:82; not repeated here.

Covered elsewhere

  • The audience/status_moved/_assigned_instance imports from cover.py, merged.py, isolation.py, seats.py, setup_cards.py, takeovers.py, jourfixe/*, moderation.py: tsk-dwrtrhdgzezs.
  • cards.set_depends_on/would_cycle, set_ships_with vs set_symmetric, open_dependencies vs releases._shipped: tsk-92tjmmcfvwm4 items 1-3.
  • Searched: task_updated, _touch_parents, _closing, _lease_active, report_key, _project_card, audience.

Effort sum: M + 6S (about 9 points).