8000 Collection Helper should not make redundant COUNT queries. · activeadmin/activeadmin@116e621 · GitHub
[go: up one dir, main page]

Skip to content

Commit 116e621

Browse files
Collection Helper should not make redundant COUNT queries.
1 parent f82cffc commit 116e621

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/active_admin/helpers/collection.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module Helpers
44
module Collection
55
# 1. removes `select` and `order` to prevent invalid SQL
66
# 2. correctly handles the Hash returned when `group by` is used
7+
# 3. Avoids duplicative COUNT/subquery_for_count queries
78
def collection_size(c = collection)
8-
return c.count if c.is_a?(Array)
9-
return c.length if c.limit_value
9+
# 'length' avoids count query on unloaded collection with a limit_value
10+
return c.length if c.is_a?(Array) || c.limit_value.present?
1011

1112
c = c.except :select, :order
12-
13-
c.group_values.present? ? c.count.count : c.count
13+
c.group_values.present? ? c.size.size : c.size
1414
end
1515

1616
def collection_is_empty?(c = collection)

0 commit comments

Comments
 (0)
0