improve performance #2

apikeys
Laurent 4 months ago
parent 0a6b4614fe
commit 1e958cca57
  1. 9
      tournaments/models/tournament.py

@ -506,7 +506,7 @@ class Tournament(BaseModel):
group_stage = self.group_stages.filter(id=group_stage_id).first() 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)) match_groups.append(self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=False))
elif round_id: elif round_id:
round = self.rounds.filter(id=round_id).first() round = self.rounds.filter(id=round_id).first().prefetch_related('matches')
if round and display_brackets is True: if round and display_brackets is True:
match_groups = self.round_match_groups(round, broadcasted, hide_empty_matches=False) match_groups = self.round_match_groups(round, broadcasted, hide_empty_matches=False)
else: else:
@ -518,12 +518,13 @@ class Tournament(BaseModel):
groups = [] groups = []
if self.display_matches(): if self.display_matches():
rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index') rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index').prefetch_related('matches')
for round in rounds: for round in rounds:
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True))
if self.display_group_stages(): if self.display_group_stages():
for round in self.rounds.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index'): rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index').prefetch_related('matches')
for round in rounds:
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True))
group_stages = sorted(self.sorted_group_stages(), key=lambda s: (-s.step, s.index)) group_stages = sorted(self.sorted_group_stages(), key=lambda s: (-s.step, s.index))
@ -609,7 +610,7 @@ class Tournament(BaseModel):
def sorted_group_stages(self): def sorted_group_stages(self):
# Get all group stages and sort by step (descending) and index (ascending) # Get all group stages and sort by step (descending) and index (ascending)
group_stages = self.group_stages.all().order_by('-step', 'index') group_stages = self.group_stages.all().order_by('-step', 'index').prefetch_related('matches')
# List to collect live group stages from finished steps # List to collect live group stages from finished steps
filtered = [] filtered = []

Loading…
Cancel
Save