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:
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
[x] I have opened this pull request against master
[ ] I have added or modified the tests when changing logic
[x] I have read the contribution guidelines and I have joined #workgroup-pr-review on
Slack to find a “pr review buddy” who is going to review my pull request.
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