Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce time complexity for chain of * in problem filter #1658

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions judge/tasks/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fnmatch
import json
import os
import re
import zipfile

from celery import shared_task
Expand All @@ -13,6 +14,7 @@
from judge.utils.unicode import utf8bytes

__all__ = ('prepare_user_data',)
rewildcard = re.compile(r'\*+')


def apply_submission_filter(queryset, options):
Expand All @@ -24,9 +26,12 @@ def apply_submission_filter(queryset, options):
if options['submission_results']:
queryset = queryset.filter(result__in=options['submission_results'])

if options['submission_problem_glob'] != '*':
# Compress wildcards to avoid exponential complexity on certain glob patterns before Python 3.9.
# For details, see <https://bugs.python.org/issue40480>.
problem_glob = rewildcard.sub('*', options['submission_problem_glob'])
if problem_glob != '*':
queryset = queryset.filter(
problem__in=Problem.objects.filter(code__regex=fnmatch.translate(options['submission_problem_glob'])),
problem__in=Problem.objects.filter(code__regex=fnmatch.translate(problem_glob)),
)

return list(queryset)
Expand Down