issue.stored_event_count: consequences for 'irrelevance'

document & assert
This commit is contained in:
Klaas van Schelven
2025-03-31 15:25:59 +02:00
parent ce87d901a1
commit a097e25310
2 changed files with 7 additions and 0 deletions

View File

@@ -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))

View File

@@ -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):