Skip to content

Commit

Permalink
Consistently cache global submission stats
Browse files Browse the repository at this point in the history
Instead of using the problems visible to whatever user populating
the cache, we simply cache stats all submissions on the site.
  • Loading branch information
quantum5 committed May 8, 2021
1 parent 1e4765b commit e53bfeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions judge/views/ranked_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def get_content_title(self):
return format_html(_('Best solutions for <a href="{1}">{0}</a>'), self.problem_name,
reverse('problem_detail', args=[self.problem.code]))

def _get_result_data(self):
return get_result_data(super(RankedSubmissions, self).get_queryset().order_by())
def _get_result_data(self, queryset=None):
return get_result_data((queryset or super(RankedSubmissions, self).get_queryset()).order_by())


class ContestRankedSubmission(ForceContestMixin, RankedSubmissions):
Expand Down
12 changes: 6 additions & 6 deletions judge/views/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def get_result_data(self):
category['name'] = _(category['name'])
return result

def _get_result_data(self):
return get_result_data(self.get_queryset().order_by())
def _get_result_data(self, queryset=None):
return get_result_data((queryset or self.get_queryset()).order_by())

def access_check(self, request):
pass
Expand Down Expand Up @@ -504,15 +504,15 @@ def get_context_data(self, **kwargs):
context['stats_update_interval'] = self.stats_update_interval
return context

def _get_result_data(self):
if self.in_contest or self.selected_languages or self.selected_statuses:
return super(AllSubmissions, self)._get_result_data()
def _get_result_data(self, queryset=None):
if queryset or self.in_contest or self.selected_languages or self.selected_statuses:
return super(AllSubmissions, self)._get_result_data(queryset)

key = 'global_submission_result_data'
result = cache.get(key)
if result:
return result
result = super(AllSubmissions, self)._get_result_data()
result = super(AllSubmissions, self)._get_result_data(Submission.objects.all())
cache.set(key, result, self.stats_update_interval)
return result

Expand Down

0 comments on commit e53bfeb

Please sign in to comment.