oliver-zehentleitner / maity
clean-up: G2 releases and probe: release readiness recomputed on every card write, observation lookups copied, the open-release select four times
tsk-j4000xbasxty 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.
releases.py and probe.py: one slow path on the card write routes, and duplicated reads of forge_observation and of the open release.
1. releases.recheck recomputes the whole readiness on every card write (slow path on hot routes)
- Callers:
routes/tasks.py:982(create),:1268(PATCH),:1331(moderation cancel),:2117(report),:2256(checklist tick), andprobe.py:190,:531(every stored observation). - What it costs: while a release is in flight,
recheck(releases.py:287-309) buildsrelease_view, which runs_live(198-204). That is the shipped cards, oneforge_observationselect per pull request (pull_requests,87-103), one select per frontier step for theships_withgroups (106-130), andprobe_configured(186-195, a project select plusforge_access.instance_serves). It runs whatever the write touched: a title edit on an unrelated card pays for the whole release. - A PATCH that closes a release card computes
_livethree times in one write:_refuse_unready(routes/tasks.py:461),releases.close(releases.py:268) andrecheck(releases.py:300). - Proposal (pick one):
- (a)
recheckonly when the write can change readiness: the release card itself, a card it depends on (a status or report change), aships_withedge, or an observation. The callers know which. - (b) Keep calling it everywhere, but compute
_liveonce per transaction (memoise on the connection) and letcloseand_refuse_unreadyreuse it. - Effort: M. Risk: medium. A missed recheck means a missed
release_ready.test_releases.pycovers the turns to ready and back; add one test per write kind that can change readiness.
2. The probe builds a whole release view only to read the PR numbers (slow path)
probe.py:374(_announce_for_release, on every changedprobservation) andprobe.py:665-668(observe_release, every sweep) callreleases.release_view(...)["pull_requests"]. That also computes groups, readiness andprobe_configured, and reads the tag.- Proposal: a
releases.pr_numbers(conn, card)that reads only the shipped cards' reported PRs and the typed ones (the first half ofpull_requests, without the observations). - Effort: S. Risk: low.
3. The forge_observation row is read and written in several places (duplication)
- Read by
(project, kind, ref):probe.py:87-94(_cached),releases.py:36-48(_observation),merged.py:102-108(inside_merge_sha). - The delete-then-insert upsert:
probe.py:168-179(_put) andprobe.py:322-337(_kept). - "The data plus
observed_at":releases.py:46-47,releases.py:253(tags),probe.py:82-84(Observation.stamped). - Proposal: one small set in
probe.py(or anobservations.pythat both import):row(conn, project_id, kind, ref),replace(conn, project_id, kind, ref, observed_at, data)andstamped(row).releasesandmergedread through it. - Effort: S. Risk: low.
4. "The project's open release card" is selected four times (duplication)
probe.py:364-368,probe.py:658-662,releases.py:293-297,routes/tasks.py:322-326(therelease_in_flightcheck in_new_release).- Proposal:
releases.open_release(conn, project_id) -> Row | None. - Effort: S. Risk: none.
5. observe_report reads the same events twice in a row (slow path / duplication)
probe.py:519-520calls_last_announced(615-641) and then_last_observed(585-607). Both select the card's lastANNOUNCED_LOOKBACKprobe_observedevents with the same filter and order; only the scan of the rows differs.- Proposal: read the rows once and pass them to both scans.
- Effort: S. Risk: none.
6. Small copies inside probe.py (duplication)
_guarded(981-990) is_covered(993-1010) without theNotCoveredErrorbranch._guardedcan be_coveredwith a throwaway set, or both can share the except chain.sweepopens two connections back to back (728-739,740-747). The second query (projects with a public page) can run in the first block, or be derived from the first rows if they selectpublic_page.announce_merges(820) andannounce_deploy(910) select the project inline although_project(428-430) exists.- Proposal: as stated. Effort: S. Risk: none.
7. A release's version is read with a fallback that never fires, and an unused constant (debt)
releases.py:219,237,271readrelease_data.get("version") or card.release_version. Both values are written together at creation (routes/tasks.py:335-340), and nothing patches either (ReleasePatchInhas no version). The fallback can only matter for a row withoutrelease_data.version, which no code path writes; the alpha keeps no legacy rows.releases.PR_STATES(releases.py:25) has no reader (repo-wide grep).- Proposal: read
card.release_version(the column carries the uniqueness constraint), dropversionfromrelease_dataor keep it only for the view, and deletePR_STATES. - Effort: S. Risk: low.
test_releases.pycovers the release view.
Order
- Do item 4 before item 1 (both touch
recheck). - Item 3 touches
merged.pylike the G2 bug card onmerged_closesfiled at the same time; rebase rather than conflict. - tsk-92tjmmcfvwm4 item 3 changes
releases._shipped; rebase rather than conflict.
Covered elsewhere
releases._shippedvscards.open_dependencies: tsk-92tjmmcfvwm4 item 3.probe.Worker(and its broadexceptatprobe.py:1070): tsk-dzpzpn5xrm5j item 1.- Searched: recheck, release_view, release_in_flight, forge_observation, _last_announced, PR_STATES.
Effort sum: M + 6S (about 9 points).