fix: Unnecessary complexity in current_content
query set
#417
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.
Description
Due to a typo, the
current_content()
method of the admin manager of versioned objects had quadratic instead of linear complexity in the number of version objects in the database.For most day-to-day situations, this is not relevant, since mostly single or only a few content objects are fetched.
For large query sets, such as when the menu tree is built, this has a tremendous impact.
Functionally, the change is irrelevant. Also, on Python level there is no impact. The performance gain comes solely from the database.
When testing with SQLite, 50.000 pages a db hit for the single query set reduced from 5 minutes to 1 second.
Explanation
Before the change in
current_content()
method of the queryset injected into versioned models:After - change is in the last line (other changes in the PR are cosmetics, really):
Before the change, the qs filters relevant versions, and then the returned qs does it again. This leads to two inner joints on versions (n^2 complexity).
After the change, the qs filters the relevant versions, and then filters the original qs (self) : One inner joint, linear complexity.
Checklist
master
Slack to find a “pr review buddy” who is going to review my pull request.