From 4d398b121d8ec368eff7ec11edfe9c37e7426877 Mon Sep 17 00:00:00 2001 From: Florian Aucomte Date: Thu, 29 Feb 2024 14:02:51 +0000 Subject: [PATCH] fix: Only target recent attempts (#1587) --- .../0090_add_missing_model_solutions.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/game/migrations/0090_add_missing_model_solutions.py b/game/migrations/0090_add_missing_model_solutions.py index 2f166c461..1a2b53659 100644 --- a/game/migrations/0090_add_missing_model_solutions.py +++ b/game/migrations/0090_add_missing_model_solutions.py @@ -1,8 +1,13 @@ +import datetime +import logging import re +import pytz from django.apps.registry import Apps from django.db import migrations +LOGGER = logging.getLogger(__name__) + def add_missing_model_solutions(apps: Apps, *args): Level = apps.get_model("game", "Level") @@ -48,9 +53,14 @@ def add_missing_model_solutions(apps: Apps, *args): "91", ], score=10, + finish_time__gte=datetime.datetime(2023, 3, 1, 00, 00, tzinfo=pytz.UTC), ).prefetch_related("level") - for attempt in attempts.iterator(chunk_size=500): + LOGGER.info(f"Retrieved {attempts.count()} attempts.") + + processed_count = 0 + + for attempt in attempts.iterator(chunk_size=1000): workspace = attempt.workspace # Get number of blocks from solution - 1 to discount Start block @@ -72,6 +82,11 @@ def add_missing_model_solutions(apps: Apps, *args): attempt.save() + processed_count += 1 + + if processed_count % 1000 == 0: + LOGGER.info(f"Processed {processed_count} attempts.") + def remove_new_model_solutions(apps: Apps, *args): Level = apps.get_model("game", "Level") @@ -115,6 +130,7 @@ def remove_new_model_solutions(apps: Apps, *args): "91", ], score__gt=10, + finish_time__gte=datetime.datetime(2023, 3, 1, 00, 00, tzinfo=pytz.UTC), ).update(score=10)