activeadmin / activeadmin-mongoid

ActiveAdmin hacks to support Mongoid
MIT License
192 stars 210 forks source link

Use only one query to count items in a collection #70

Closed trekdemo closed 7 years ago

trekdemo commented 10 years ago

Hi Guys,

Is there a reason for firing 3 queries to count items in a collection?

The previous version caused 3 queries:

  1. collection.empty? #=> load an item to ensure there are items in the collection
  2. collection.first ... #=> load an item again to be sure about we querying mongo
  3. collection.count(true) #=> actual count command