-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Collection Helper should not make redundant COUNT queries. #7489
base: master
Are you sure you want to change the base?
Collection Helper should not make redundant COUNT queries. #7489
Conversation
c162581
to
116e621
Compare
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.
Thanks for tackling this! Would you consider adding some specs for the cases you've mentioned? It would help to have some more coverage around this as we'd appreciate any help and input on improving that.
Guys any plans to merge this PR? |
Can you help us add a spec? |
Just checked this fork on my project and I still get |
So what you're saying is that this does not actually work? |
Right now, in my case
something like this, then you use filter on one of the columns, it still generates heavy |
@Nkadze if you want to solve this, you can set the
I've applied this snippet as a monkey patch, and it works fine. Are you planning to merge this PR? |
There is also a problem when using pagination_total: false with
We monkey-patched it with |
I have been looking into why
pagination_total: false
is not preventing the execution of multiplesubquery_for_count
queries. I found the issue appeared rooted in thecollection_size
method not validating whether a collection is already loaded. General context on my changes:count
, this triggers several redundant count subqueries (subquery_for_count
) that cause latency and even timeouts when loading index pagesArray#length
should be more performant thanArray#count
within this contextResolves #6492, #2638
Testing/QA
Because this is a refactor and not new behavior I did not add new specs. When looking into this, I did come across some bugs in the paginated collection specs that should probably be fixed at some point though; for example, the examples pertaining to pagination_total will always result in a false pass because they're testing for the absence of queries that will never occur, and it's going uncaught because the author did not test the opposite assertion when the option is false.
I've QA'd this as an override in a staging environment that uses a sanitized production DB snapshot by loading index pages for tables that I know to have millions of records. The staging environment has fewer computing resources, but after pushing this change it is rendering large index pages faster than the production environment — it's even rendering
pagination_total: false
pages that are timing out in production (due to the COUNT subqueries).In a development environment, I can also see that this prevents the redundant COUNT subqueries that drive many of us to attempt using the
pagination_total
option; here is my sanitized server log:Before
After