Skip to content

Commit

Permalink
fix: Only target recent attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Feb 29, 2024
1 parent 7faa398 commit e4542ca
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion game/migrations/0090_add_missing_model_solutions.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -72,6 +82,11 @@ def add_missing_model_solutions(apps: Apps, *args):

attempt.save()

processed_count += 1

Check warning on line 85 in game/migrations/0090_add_missing_model_solutions.py

View check run for this annotation

Codecov / codecov/patch

game/migrations/0090_add_missing_model_solutions.py#L85

Added line #L85 was not covered by tests

if processed_count % 1000 == 0:
LOGGER.info(f"Processed {processed_count} attempts.")

Check warning on line 88 in game/migrations/0090_add_missing_model_solutions.py

View check run for this annotation

Codecov / codecov/patch

game/migrations/0090_add_missing_model_solutions.py#L87-L88

Added lines #L87 - L88 were not covered by tests


def remove_new_model_solutions(apps: Apps, *args):
Level = apps.get_model("game", "Level")
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit e4542ca

Please sign in to comment.