Skip to content

Commit

Permalink
Revert and replace "Small rankingsd optimization"
Browse files Browse the repository at this point in the history
This reverts commit fb47b2e,
which was duplicating existing caching functionality, while also
creating some bug(s?).
  • Loading branch information
otargowski committed Apr 17, 2024
1 parent 87bca08 commit db964f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
18 changes: 5 additions & 13 deletions oioioi/contests/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,8 @@ def get_user_public_name(self, request, user):
if the former is not available.
"""
return get_user_display_name(user)

def get_round_times_in_bulk(self, request):
if request is not None:
return rounds_times(request, self.contest)
else:
return generic_rounds_times(None, self.contest)

def get_round_times(self, request, round, preprocessed=None):
def get_round_times(self, request, round):
"""Determines the times of the round for the user doing the request.
The default implementation returns an instance of
Expand All @@ -410,13 +404,11 @@ def get_round_times(self, request, round, preprocessed=None):
Request is optional (round extensions won't be included if omitted).
:returns: an instance of :class:`RoundTimes`
:param preprocessed: if one already called get_round_times_in_bulk,
then one should pass them here.
"""
if preprocessed != None:
return preprocessed[round]
return self.get_round_times_in_bulk(request)[round]
if request is not None:
return rounds_times(request, self.contest)[round]
else:
return generic_rounds_times(None, self.contest)[round]

def separate_public_results(self):
"""Determines if there should be two separate dates for personal
Expand Down
5 changes: 2 additions & 3 deletions oioioi/phase/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.views.decorators.http import require_POST

from oioioi.base.permissions import enforce_condition
from oioioi.clock.views import get_round_times
from oioioi.contests.models import Round, UserResultForProblem
from oioioi.contests.utils import contest_exists, is_contest_admin
from oioioi.phase.controllers import _FirstPhase
Expand Down Expand Up @@ -68,9 +69,7 @@ def get_phases_status(request, response):
qs = Round.objects.filter(contest=contest)
rounds = []
cc = contest.controller
rtimes_prp = cc.get_round_times_in_bulk(request)
for r in qs:
rtime = cc.get_round_times(request, r, rtimes_prp)
for rtime, r in get_round_times(request):
if cc.can_see_round(request, r) and rtime.is_active(timestamp):
rounds.append(r)
# Ordered by start date by default
Expand Down
5 changes: 3 additions & 2 deletions oioioi/rankings/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ def _iter_rounds(self, can_see_all, timestamp, partial_key, request=None):
queryset = self.contest.round_set.all()
if partial_key != CONTEST_RANKING_KEY:
queryset = queryset.filter(id=partial_key)
times_list = ccontroller.get_round_times_in_bulk(request)
# A not-None request enables caching of round times
request = request or self._fake_request(1)
for round in queryset:
times = ccontroller.get_round_times(request, round, times_list)
times = ccontroller.get_round_times(request, round)
if can_see_all or times.public_results_visible(timestamp):
yield round

Expand Down

0 comments on commit db964f8

Please sign in to comment.