diff --git a/match/migrations/0051_alter_ban_unique_together_alter_team_unique_together.py b/match/migrations/0051_alter_ban_unique_together_alter_team_unique_together.py new file mode 100644 index 00000000..2a0a30c6 --- /dev/null +++ b/match/migrations/0051_alter_ban_unique_together_alter_team_unique_together.py @@ -0,0 +1,21 @@ +# Generated by Django 5.1.1 on 2024-10-12 20:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('match', '0050_remove_match_is_fully_imported_and_more_updated'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='ban', + unique_together={('team', 'pick_turn')}, + ), + migrations.AlterUniqueTogether( + name='team', + unique_together={('_id', 'match')}, + ), + ] diff --git a/match/models.py b/match/models.py index 5ea42359..fdfc9640 100644 --- a/match/models.py +++ b/match/models.py @@ -875,6 +875,9 @@ class Team(models.Model): def __str__(self): return f"Team(match={self.match._id}, _id={self._id})" + class Meta: + unique_together = ("_id", "match") + class Ban(models.Model): id: int | None @@ -885,6 +888,9 @@ class Ban(models.Model): def __str__(self): return f"Ban(team={self.team._id}, match={self.team.match._id})" + class Meta: + unique_together = ("team", "pick_turn") + class Bounty(BaseModel): monster_bounty: int = 0 diff --git a/match/tasks.py b/match/tasks.py index b1612bce..08fc37b9 100644 --- a/match/tasks.py +++ b/match/tasks.py @@ -237,11 +237,21 @@ def multi_match_import(matches_json, region): unique_fields=["_id"], update_fields=["game_duration"], ) - Participant.objects.bulk_create(participants) - Stats.objects.bulk_create(stats) + Participant.objects.bulk_create( + participants, + update_conflicts=True, + unique_fields=["_id", "match_id"], + update_fields=["champion_id"], + ) + Stats.objects.bulk_create(stats, ignore_conflicts=True) Summoner.objects.bulk_create(summoners, ignore_conflicts=True) - Team.objects.bulk_create(teams) - Ban.objects.bulk_create(bans) + Team.objects.bulk_create( + teams, + update_conflicts=True, + unique_fields=["match_id", "_id"], + update_fields=["win"], + ) + Ban.objects.bulk_create(bans, ignore_conflicts=True) @app.task(name="match.tasks.import_recent_matches")