From 394f83427d6c87a199d8afc08750d66269ab26fc Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 24 Nov 2026 07:10:01 -0500 Subject: [PATCH] fix(7735): the read-already backfill touches only the rows the readers count Rows without a plugin version are skipped by every open-rate reader and are most of the table, so the correlated lookup runs on the rows recorded since 0133 only. Keeps the migration cheap on the live table, not just in CI. Co-Authored-By: Claude Opus 5.5 --- alembic/versions/0135_rule_delivery_read_already.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/alembic/versions/0135_rule_delivery_read_already.py b/alembic/versions/0135_rule_delivery_read_already.py index 470fa187..c15248f2 100644 --- a/alembic/versions/0135_rule_delivery_read_already.py +++ b/alembic/versions/0135_rule_delivery_read_already.py @@ -9,8 +9,12 @@ is stamped opened as it is written (`rule_deliveries._read_already`). This stamps the deliveries already recorded the same way, so the open rates, the adherence readout and the weighing pass read one definition across old and new rows: a rule read early in a session is not counted unread each time it -arrives again. The stamp is the delivery's own time. Not reversible: the -downgrade leaves the stamps, which the earlier code reads as ordinary opens. +arrives again. The stamp is the delivery's own time. Only rows that carry a +plugin version are touched: every reader skips the others +(`rule_deliveries.REPORTS_OPENS`), and they are most of the table, so the +lookup runs on the few rows recorded since 0133 rather than on all of them. +Not reversible: the downgrade leaves the stamps, which the earlier code reads +as ordinary opens. """ from alembic import op @@ -26,6 +30,7 @@ def upgrade() -> None: UPDATE rule_deliveries d SET opened_at = d.delivered_at WHERE d.opened_at IS NULL + AND d.plugin IS NOT NULL AND EXISTS ( SELECT 1 FROM rule_deliveries e WHERE e.user_id = d.user_id