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

Sign in to report

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), and probe.py:190, :531 (every stored observation).
  • What it costs: while a release is in flight, recheck (releases.py:287-309) builds release_view, which runs _live (198-204). That is the shipped cards, one forge_observation select per pull request (pull_requests, 87-103), one select per frontier step for the ships_with groups (106-130), and probe_configured (186-195, a project select plus forge_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 _live three times in one write: _refuse_unready (routes/tasks.py:461), releases.close (releases.py:268) and recheck (releases.py:300).
  • Proposal (pick one):
  • (a) recheck only when the write can change readiness: the release card itself, a card it depends on (a status or report change), a ships_with edge, or an observation. The callers know which.
  • (b) Keep calling it everywhere, but compute _live once per transaction (memoise on the connection) and let close and _refuse_unready reuse it.
  • Effort: M. Risk: medium. A missed recheck means a missed release_ready. test_releases.py covers 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 changed pr observation) and probe.py:665-668 (observe_release, every sweep) call releases.release_view(...)["pull_requests"]. That also computes groups, readiness and probe_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 of pull_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) and probe.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 an observations.py that both import): row(conn, project_id, kind, ref), replace(conn, project_id, kind, ref, observed_at, data) and stamped(row). releases and merged read 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 (the release_in_flight check 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-520 calls _last_announced (615-641) and then _last_observed (585-607). Both select the card's last ANNOUNCED_LOOKBACK probe_observed events 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 the NotCoveredError branch. _guarded can be _covered with a throwaway set, or both can share the except chain.
  • sweep opens 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 select public_page.
  • announce_merges (820) and announce_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, 271 read release_data.get("version") or card.release_version. Both values are written together at creation (routes/tasks.py:335-340), and nothing patches either (ReleasePatchIn has no version). The fallback can only matter for a row without release_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), drop version from release_data or keep it only for the view, and delete PR_STATES.
  • Effort: S. Risk: low. test_releases.py covers the release view.

Order

  • Do item 4 before item 1 (both touch recheck).
  • Item 3 touches merged.py like the G2 bug card on merged_closes filed at the same time; rebase rather than conflict.
  • tsk-92tjmmcfvwm4 item 3 changes releases._shipped; rebase rather than conflict.

Covered elsewhere

  • releases._shipped vs cards.open_dependencies: tsk-92tjmmcfvwm4 item 3.
  • probe.Worker (and its broad except at probe.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).