-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Revert PR #4068 and use pagination_total optimization with decorators #5389
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5389 +/- ##
==========================================
+ Coverage 98.33% 98.33% +<.01%
==========================================
Files 294 294
Lines 11033 11035 +2
==========================================
+ Hits 10849 10851 +2
Misses 184 184
Continue to review full report at Codecov.
|
Oops, paginated_collection_spec is not passing.
Queries like `SELECT COUNT(*) FROM (SELECT DISTINCT resources.* FROM resources ORDER BY resources.created_at DESC LIMIT 1 OFFSET 30) subquery_for_count` are too inefficient
@varyonic fixed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Sean noted on my original PR a test would be nice, but I agree this is a better fix.
# The #paginate method in kaminari will query the resource with a | ||
# count(*) to determine how many pages there should be unless | ||
# you pass in the :total_pages option. We issue a query to determine | ||
# if there is another page or not, but the limit/offset make this | ||
# query fast. | ||
offset = collection.offset(collection.current_page * @per_page.to_i).limit(1).count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the check for responding to offset
no longer required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was never required (https://github.com/activeadmin/activeadmin/pull/4068/files#diff-a388362633460ba06e0a1f38bbb8ce1aR103) - it was just a different way to optimize.
Any update on my question for the Is there a way to time out queries in a multi-database way to only allocate a certain amount of time for count queries? |
Maybe... but this is certainly out of scope :) I really wanted to get rid of the monkey patch from my apps 😭 |
@rafaelsales Sorry for missing this PR. We have (at least partially) fixed this in #5811. I should've included you in the author's list because the solution originates from this PR, sorry about that. This PR includes some extra changes that are probably further optimizations. Would you like to rebase this PR so we can also add those improvements? Thanks! |
Rebased as #6911. |
The PR #3848 introduced an optimization that prevents COUNT queries when using
index pagination_total: false
.I noticed that when using the macro
decorate_with
, the optimization didn't work and the count query across the entire database was made. That is because the AA default collection decorator didn't implementoffset
. I believe the PR #4068 made the wrong fix for thisoffset
to AR relationSELECT COUNT(*) FROM (SELECT DISTINCT resources.* FROM resources ORDER BY resources.created_at DESC LIMIT 1 OFFSET 30) subquery_for_count
are very inefficient