I have an action which does a simple query which executes quickly, but for some reason it also executes a count()
command, which I didn't ask for:
In the controller:
@things = Thing.active.where(city: "New York", state: "New York).limit(10).desc(:qs)
And in the logs:
MOPED: 127.0.0.1:27017 QUERY database=dirot_development collection=things selector={"$query"=>{"status"=>"available", "city"=>"New York", "state"=>"New York"}, "$orderby"=>{"qs"=>-1}} flags=[:slave_ok] limit=10 skip=0 fields=nil (3.8438ms)
MOPED: 127.0.0.1:27017 KILL_CURSORS cursor_ids=[3455573564096875000] (0.0620ms)
MOPED: 127.0.0.1:27017 COMMAND database=dirot_development command={:count=>"things", :query=>{"status"=>"available", "city"=>"New York", "state"=>"New York"}} (378.4430ms)
As you can see from the log, doing the count takes 378ms while actually getting the 10 documents that I want takes barely 4ms. How can I eliminate the count?
I am using will_paginate, but not in this particular action/view.
Any ideas?
* UPDATE *
Active is just a standard scope: scope :active, where(status: "available")