8000 Remove ORDER BY from count subquery · activeadmin/activeadmin@6fd65f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fd65f2

Browse files
committed
Remove ORDER BY from count subquery
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
1 parent 38e2d4c commit 6fd65f2

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/active_admin/resource_controller/decorators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def self.wrap!(parent, name)
6868
::Class.new parent do
6969
delegate :reorder, :page, :current_page, :total_pages, :limit_value,
7070
:total_count, :offset, :to_key, :group_values, :except,
71-
:find_each, :ransack
71+
:reorder, :find_each, :ransack
7272

7373
define_singleton_method(:name) { name }
7474
end

lib/active_admin/views/components/paginated_collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def build_pagination
102102
# you pass in the :total_pages option. We issue a query to determine
103103
# if there is another page or not, but the limit/offset make this
104104
# query fast.
105-
offset = collection.offset(collection.current_page * @per_page.to_i).limit(1).count
105+
offset = collection.reorder(nil).offset(collection.current_page * @per_page.to_i).limit(1).count
106106
options[:total_pages] = collection.current_page + offset
107107
options[:right] = 0
108108
end

0 commit comments

Comments
 (0)
0