diff --git a/neonwatch/store.py b/neonwatch/store.py index 10d7e87..2385ebe 100644 --- a/neonwatch/store.py +++ b/neonwatch/store.py @@ -307,7 +307,9 @@ class AuditEntry: "DELETE FROM links WHERE at < ?", "DELETE FROM links_latest WHERE at < ?", "DELETE FROM analyses WHERE completed_at < ?", - "DELETE FROM notified WHERE at < ?", + # A live issue keeps its record however old, or a restart would send it again. + "DELETE FROM notified WHERE at < ? AND issue_id NOT IN " + "(SELECT id FROM issues WHERE state != 'resolved')", ) #: Size-pruning tiers, each the oldest rows first: every history table merged in time order, diff --git a/neonwatch/store_test.py b/neonwatch/store_test.py index cee92fd..3e15660 100644 --- a/neonwatch/store_test.py +++ b/neonwatch/store_test.py @@ -667,6 +667,17 @@ def test_a_notification_keeps_the_highest_rank_sent_and_the_latest_time(tmp_path s.close() +def test_a_live_issue_keeps_its_notification_past_retention(tmp_path: Path) -> None: + s = Store(tmp_path / "store.sqlite3", config(max_age_s=100)) + s.apply(issue_event(issue("open", updated_at=10))) + s.apply(issue_event(issue("done", state=IssueState.RESOLVED, updated_at=10))) + for issue_id in ("open", "done", "gone"): + s.note_notified(issue_id, 2, 10.0) + s.prune(now=1000) + assert s.notified() == {"open": (2, 10.0)} # resolved or no longer stored: forgotten + s.close() + + def _fill(s: Store, n: int) -> None: for t in range(n): s.apply(obs_event("wide", {f"field{k}": float(t) for k in range(50)}, at=1000 + t))