From a097e253105da96da4ce5d528802accf41a6868e Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Mon, 31 Mar 2025 15:25:59 +0200 Subject: [PATCH] issue.stored_event_count: consequences for 'irrelevance' document & assert --- events/retention.py | 3 +++ issues/migrations/0013_fix_issue_stored_event_counts.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/events/retention.py b/events/retention.py index bd48852..d3a7799 100644 --- a/events/retention.py +++ b/events/retention.py @@ -83,6 +83,9 @@ def get_random_irrelevance(stored_event_count): if `cnt` "hovers" around a certain value (which is likely to happen when there's repeated eviction/fill-up). ×2 is simply to correct for random() (which returns .5 on average). """ + # assert as a tripwire to check our assumptions; note that the actual calculation actually "succeeds" for < 1, but + # it becomes non-sensical, so I'd rather have it fail. The present event is part of the count, i.e. always >= 1 + assert stored_event_count >= 1 return nonzero_leading_bits(round(random() * stored_event_count * 2)) diff --git a/issues/migrations/0013_fix_issue_stored_event_counts.py b/issues/migrations/0013_fix_issue_stored_event_counts.py index afac0d4..70037b0 100644 --- a/issues/migrations/0013_fix_issue_stored_event_counts.py +++ b/issues/migrations/0013_fix_issue_stored_event_counts.py @@ -18,6 +18,10 @@ def fill_stored_event_count(apps, schema_editor): issue.stored_event_count = correct_value issue.save() + # Note: because "irrelevances" have been calculated based on stored_event_count, those will be wrong too... but + # there doesn't seem to be an easy way to recover from that, so we'll just let the problem fix itself over time. + # easy meaning: both easy-enough to write a datamigration for, and not super-expensive to run. + class Migration(migrations.Migration):