Skip to content

Fix pagination_total index option to prevent SELECT COUNT queries#5388

Closed
rafaelsales wants to merge 1 commit intoactiveadmin:masterfrom
rafaelsales:master
Closed

Fix pagination_total index option to prevent SELECT COUNT queries#5388
rafaelsales wants to merge 1 commit intoactiveadmin:masterfrom
rafaelsales:master

Conversation

@rafaelsales
Copy link
Contributor

@rafaelsales rafaelsales commented Apr 3, 2018

The PR #3848 was supposed to make sure that paginate_total: false option prevents SELECT COUNT queries. Unfortunately, the current AA version (v1.2.1) makes count queries when paginate_total: false is provided.

The goal of this PR is to add a spec to assert on the count query and fix the issue.

paginated_collection(collection, pagination_total: false)
ActiveRecord::Base.logger = nil
expect(log.string).to_not include 'SELECT COUNT'
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the fix is not implemented yet, this spec fails:


  1) ActiveAdmin::Views::PaginatedCollection creating with the dsl with :pagination_total set to false should not perform count queries
     Failure/Error: end
       expected "D, [2018-04-02T22:48:21.957729 #82970] DEBUG -- :   \e[1m\e[35m (0.2ms)\e[0m  \e[1m\e[34mSELECT COUN...T  1 FROM \"posts\" LIMIT ? OFFSET ?) subquery_for_count\e[0m  [[\"LIMIT\", 30], [\"OFFSET\", 0]]\n" not to include "SELECT COUNT"

and the log output shows the count queries:


D, [2018-04-02T22:48:21.957729 #82970] DEBUG -- :    (0.2ms)  SELECT COUNT(*) FROM (SELECT  1 FROM "posts" LIMIT ? OFFSET ?) subquery_for_count  [["LIMIT", 1], ["OFFSET", 0]]
D, [2018-04-02T22:48:22.172004 #82970] DEBUG -- :    (0.2ms)  SELECT COUNT(*) FROM (SELECT  1 FROM "posts" LIMIT ? OFFSET ?) subquery_for_count  [["LIMIT", 30], ["OFFSET", 0]]
D, [2018-04-02T22:48:22.172614 #82970] DEBUG -- :   Post Load (0.1ms)  SELECT  "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT ? OFFSET ?  [["LIMIT", 1], ["OFFSET", 0]]
D, [2018-04-02T22:48:22.175192 #82970] DEBUG -- :    (0.1ms)  SELECT COUNT(*) FROM (SELECT  1 FROM "posts" LIMIT ? OFFSET ?) subquery_for_count  [["LIMIT", 30], ["OFFSET", 0]]
D, [2018-04-02T22:48:22.175794 #82970] DEBUG -- :    (0.1ms)  SELECT COUNT(*) FROM (SELECT  1 FROM "posts" LIMIT ? OFFSET ?) subquery_for_count  [["LIMIT", 30], ["OFFSET", 0]]

@rafaelsales rafaelsales closed this Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant