Skip to content

Optimize Problem.name to support prefetching #507

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kyepskee
Copy link
Contributor

I changed the implementation of the name property of the Problem model. Now instead of querying the ProblemName table it goes through the names property, which can now be prefetched. This is what I do in task_archive_tag_view which dramatically speeds it up on large competitions, reducing the number of queries from linear in the number of problems to constant.

I also add a test to check that the implementations are consistent.

…ject#441)

Problem.name previously queried through the whole ProblemName table. Now
it accesses the names for the problem through self.names, which allows
other code to optimize this query by using prefetch_related on the names
property.
@kyepskee kyepskee requested a review from MasloMaslane as a code owner April 18, 2025 10:04
Previous implementation of Problem.name errored out if Problem.name was
accessed before the instance of Problem was saved with .save(). This is
now fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant