Retention, small fixes (from Friday)

This commit is contained in:
Klaas van Schelven
2024-06-23 22:20:18 +02:00
parent ea6aa9bbca
commit 5e2cc0575f
3 changed files with 26 additions and 4 deletions

View File

@@ -160,7 +160,7 @@ def evict_for_max_events(project, timestamp, stored_event_count=None):
from .models import Event
if stored_event_count is None:
# allowed as a pass-in to save a query (we generally start off knowing this)
# allowed as a pass-in to save a query (we generally start off knowing this); +1 because call-before-add
stored_event_count = Event.objects.filter(project=project).count() + 1
epoch_bounds_with_irrelevance = get_epoch_bounds_with_irrelevance(project, timestamp)
@@ -174,9 +174,11 @@ def evict_for_max_events(project, timestamp, stored_event_count=None):
# will be evicted (since `evict_for_irrelevance` will evict anything above (but not including) the given value)
max_total_irrelevance -= 1
evict_for_irrelevance(max_total_irrelevance, epoch_bounds_with_irrelevance)
evict_for_irrelevance(
max_total_irrelevance,
list(filter_for_work(epoch_bounds_with_irrelevance, pairs, max_total_irrelevance)))
stored_event_count = Event.objects.filter(project=project).count()
stored_event_count = Event.objects.filter(project=project).count() + 1
if max_total_irrelevance < -1: # < -1: see test below for why.
# could still happen ('in theory') if there's max_size items of irrelevance 0 (in the real impl. we'll have

View File

@@ -0,0 +1,20 @@
# Generated by Django 4.2.13 on 2024-06-23 20:19
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0004_event_irrelevance_for_retention'),
('issues', '0002_initial'),
]
operations = [
migrations.AlterField(
model_name='turningpoint',
name='triggering_event',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='events.event'),
),
]

View File

@@ -458,7 +458,7 @@ class TurningPoint(models.Model):
# "milestone", "state_change", "transition", "annotation", "episode"
issue = models.ForeignKey("Issue", blank=False, null=True, on_delete=models.SET_NULL) # SET_NULL: cleanup 'later'
triggering_event = models.ForeignKey("events.Event", blank=True, null=True, on_delete=models.SET_NULL)
triggering_event = models.ForeignKey("events.Event", blank=True, null=True, on_delete=models.DO_NOTHING)
# null: the system-user
user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.SET_NULL)