improve performance #4

apikeys
Laurent 4 months ago
parent c5e910a208
commit 06e9daba59
  1. 2
      tournaments/models/round.py
  2. 5
      tournaments/models/team_registration.py
  3. 6
      tournaments/models/tournament.py

@ -56,7 +56,7 @@ class Round(TournamentSubModel):
def ranking_matches(self, hide_empty_matches):
children_with_matches = self.children.prefetch_related('matches')
children_with_matches = self.children.prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations')
matches = []
for child in children_with_matches:

@ -83,15 +83,14 @@ class TeamRegistration(TournamentSubModel):
else:
return ['Place réservée']
elif player_count == 1:
players = list(self.players_sorted_by_rank)
players = self.players_sorted_by_rank
return [players[0].shortened_name(forced=forced)]
else:
players = list(self.players_sorted_by_rank)
players = self.players_sorted_by_rank
return [pr.shortened_name(forced=forced) for pr in players]
@property
def players_sorted_by_rank(self):
# Fetch related PlayerRegistration objects
return self.player_registrations.all().order_by('rank')
def player_names(self):

@ -518,12 +518,12 @@ class Tournament(BaseModel):
groups = []
if self.display_matches():
rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index').prefetch_related('matches')
rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index').prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations')
for round in rounds:
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True))
if self.display_group_stages():
rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index').prefetch_related('matches')
rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index').prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations')
for round in rounds:
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True))
@ -610,7 +610,7 @@ class Tournament(BaseModel):
def sorted_group_stages(self):
# Get all group stages and sort by step (descending) and index (ascending)
group_stages = self.group_stages.all().order_by('-step', 'index').prefetch_related('matches')
group_stages = self.group_stages.all().order_by('-step', 'index').prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations')
# List to collect live group stages from finished steps
filtered = []

Loading…
Cancel
Save