Optimization: skip COUNT query when pagination is disabled#1915
Merged
Optimization: skip COUNT query when pagination is disabled#1915
Conversation
fce89ce to
9f05ee1
Compare
4 tasks
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1915 +/- ##
==========================================
- Coverage 92.25% 92.19% -0.06%
==========================================
Files 437 437
Lines 14858 14883 +25
Branches 2450 2464 +14
==========================================
+ Hits 13707 13722 +15
- Misses 708 714 +6
- Partials 443 447 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This PR eliminates the SQL
COUNT(*)query when pagination is disabled (either via options or the query string) for GET requests. As all resources are being returned in this case, they can simply be counted in-memory to settotalin the response.Additionally, this PR slightly changes the execution order of resource-definition callbacks for certain GET requests and eliminates redundant ones. Before any SQL executes, all callbacks are invoked now. This is needed to determine whether pagination is active, so we can possibly skip the COUNT query. As a result:
GET /blogs: No longer calls the firstOnApplyFilter, which was used to prepare the COUNT query. Related to that, theIQueryLayerComposer.GetPrimaryFilterFromConstraintsmethod has been marked obsolete because it is no longer used.GET /blogs/1/postsandGET /blogs/1/relationships/posts:OnApplyFiltercallbacks for left/right to determine count happen after the callbacks for fetching data. They don't happen at all when the optimization kicks in.In the unlikely case your resource definition callbacks depend on execution order, it is recommended to verify that nothing broke.
Finally, this PR fixes a bug in the NoEntityFrameworkExample where
totalwas not always returned.Closes #1752.
QUALITY CHECKLIST