More performance optimizations#756
Open
otargowski wants to merge 14 commits into
Open
Conversation
Make all problem instances in the contest available with caching and prefetches, not only the visible ones. Use visible_problem_instances in more places
When an incomplete list of related objects is provided, then a warning is issued and the missing objects are prefetched from the db.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



A continuation of #690. A few last views were improved to use O(1) queries, most notably the submit view (I found a not too invasive way with
prefetch_related) and contest rules view.Other than that, many
prefetch_relatedcalls were replaced with newannotate_known_related[_many]utilities, which make use of already known related objects, e.g. forSubmission.objects.filter(problem_instance__in=problem_instances), we can "annotate"problem_instances. This has the huge benefit of not needing to prefetch transitively related objects all the time, likeround,problemandcontestin the example, which makes the code cleaner and less prone to someone forgetting to prefetch some relation in the future.eval_contest_submissions_qs_with_common_relatedwas also introduced, which annotates already fetched problem instances with all their related objects and also prefetches stuff foroioioi.scoresrevealif it is enabled (now this uglyifis in one place instead of a few).There are also a few other small optimizations and cleanups.