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
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,:2250merged.py:164,:193routes/board.py:107(insidechanged, 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 samesubject=("task", id)and almost alwaysaudience(conn, card). Two of them have already lost required keys (bug card filed at the same time).board.changedis already most of the helper. - Proposal: one
emit_task_updated(conn, card, project_state, values, *, history=(), actor=None, signature=None, extra_audience=())next toaudience. It derivesfieldsfromvaluesand dropsbody. All 14 sites use it.board.changedkeeps only itsupdated_atwrite and thehistory.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 incancel_by_moderation),merged.py:179-203(_touch_parent). The merged copy also counts the children itself (merged.py:186-189), which repeatsviews._task_views(views.py:1138-1143). - Proposal: one
touch_parents(conn, project, parent_ids, actor, fg)that takes anActor(notmine/caller), used by all three. The counts always come fromtask_view(...)["children"]. - Effort: S. Risk: low.
3. The columns of a close are written twice (duplication)
- Sites:
routes/tasks.py:401-410(_closing) andmerged.py:206-220(_close). Both setclosed_at, clearstatus_before_blockandblocked_by_request, and clearrelease_in_flightfor a release.routes/tasks.py:2048also setsclosed_atagain after_closinghas set it. - Proposal:
merged._closeuses_closing(once it lives in a domain module, see the Order note on tsk-dwrtrhdgzezs). Drop the secondclosed_atinreport. - Effort: S. Risk: low. The release part matters for the bug card on
merged_closesfiled 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), butrelease(1573-1579) andassign(1749-1755) build the same 409 by hand. The hand-built copies also drop theif card.lease_until else Noneguard._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 withoutobservedandmismatch, hashed) andprobe.py:535-537(_core: the same filter). Both decide whether a report is still the one an observation belongs to.- Proposal:
probe._corecalls a sharedmerged.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-89writes the same select inline, although the module already imports fromroutes/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) inaccess.pyor the domain module that tsk-dwrtrhdgzezs step 2 creates, and deleteboard._card. - Effort: S. Risk: none.
7. audience() makes one query per party (slow path on every card event)
routes/tasks.py:282-303:principal_idruns once for each of up to five parties (creator, assignee, area owner, holder, extras), each a single-row select, pluscards.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_instanceandcancel_by_moderationout ofroutes/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-950and1141-1149; rebase rather than conflict. - tsk-p3a14j8p1rg9 already lists the inline
project_closedatroutes/tasks.py:562and:1653, androutes/board.py:82; not repeated here.
Covered elsewhere
- The
audience/status_moved/_assigned_instanceimports fromcover.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_withvsset_symmetric,open_dependenciesvsreleases._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).