From c5e910a20891677c268ec1cd8093329dd868345f Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 28 Jul 2025 11:15:28 +0200 Subject: [PATCH] performance #3 --- tournaments/models/match.py | 7 ++++--- tournaments/models/team_registration.py | 8 +++++--- tournaments/models/tournament.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tournaments/models/match.py b/tournaments/models/match.py index 112b7af..08a4b42 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -194,13 +194,14 @@ class Match(TournamentSubModel): teams = [] # Check if team scores exist + team_scores_count = self.team_scores.count() team_scores = list(self.team_scores.all()) previous_top_match = self.precedent_match(True) previous_bottom_match = self.precedent_match(False) loser_top_match = self.loser_precedent_match(True) loser_bottom_match = self.loser_precedent_match(False) - if len(team_scores) == 0 or hide_names is True: + if team_scores_count == 0 or hide_names is True: if (self.round and self.round.parent is None and self.round.tournament.rounds.filter(parent__isnull=True, group_stage_loser_bracket=False).count() - 1 == self.round.index): names = ["Qualifié"] @@ -248,7 +249,7 @@ class Match(TournamentSubModel): names = [f"Gagnant {previous_bottom_match.computed_name()}"] team = self.default_live_team(names) teams.append(team) - elif len(team_scores) == 1: + elif team_scores_count == 1: # Only one team score, handle missing one existing_team = team_scores[0].live_team(self, short_names=short_names) if (self.group_stage): @@ -288,7 +289,7 @@ class Match(TournamentSubModel): teams.append(team) teams.append(existing_team) - elif len(team_scores) == 2: + elif team_scores_count: # Both team scores present teams.extend([team_score.live_team(self, short_names=short_names) for team_score in team_scores]) diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index a40af2f..02ad873 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -74,17 +74,19 @@ class TeamRegistration(TournamentSubModel): if self.name: return [self.name] #add an empty line if it's a team name else: - players = list(self.players_sorted_by_rank) - if len(players) == 0: + player_count = self.player_registrations.count() + if player_count == 0: if self.wild_card_bracket: return ['Place réservée wildcard'] elif self.wild_card_group_stage: return ['Place réservée wildcard'] else: return ['Place réservée'] - elif len(players) == 1: + elif player_count == 1: + players = list(self.players_sorted_by_rank) return [players[0].shortened_name(forced=forced)] else: + players = list(self.players_sorted_by_rank) return [pr.shortened_name(forced=forced) for pr in players] @property diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index cccc811..de27e40 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -506,7 +506,7 @@ class Tournament(BaseModel): group_stage = self.group_stages.filter(id=group_stage_id).first() match_groups.append(self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=False)) elif round_id: - round = self.rounds.filter(id=round_id).first().prefetch_related('matches') + round = self.rounds.filter(id=round_id).first() if round and display_brackets is True: match_groups = self.round_match_groups(round, broadcasted, hide_empty_matches=False) else: