Ruby on rails Mongoid 3/Moped中的限制(10)对整个集合执行count()
我有一个操作,它执行一个简单的查询,执行速度很快,但出于某种原因,它还执行一个Ruby on rails Mongoid 3/Moped中的限制(10)对整个集合执行count(),ruby-on-rails,performance,mongodb,mongoid,mongoid3,Ruby On Rails,Performance,Mongodb,Mongoid,Mongoid3,我有一个操作,它执行一个简单的查询,执行速度很快,但出于某种原因,它还执行一个count()命令,我没有要求: 在控制器中: @things = Thing.active.where(city: "New York", state: "New York).limit(10).desc(:qs) 在日志中: MOPED: 127.0.0.1:27017 QUERY database=dirot_development collection=things selector={"$qu
count()
命令,我没有要求:
在控制器中:
@things = Thing.active.where(city: "New York", state: "New York).limit(10).desc(:qs)
在日志中:
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)
从日志中可以看出,进行计数需要378ms,而实际获取我想要的10个文档只需要4ms。我怎样才能消除计数
我使用的是will_paginate,但不是在这个特定的动作/视图中
有什么想法吗
*更新*
Active只是一个标准的作用域:
scope:Active,where(状态:“可用”)
您可以显示您的.Active
方法吗?它只是作用域:Active,where(状态:“可用”)