1
私はMongoDB(Mongoid付き)を使っています。私のアプリでは本当に頻繁に実行されるクエリを持っています。クエリをより効率的にするために適切なインデックスを設定しているかどうかわかりません。クエリが実行されます:インデックスを適切に使用すると多くのクエリが防止されますか?
MONGODB (33ms) recipes_development['system.namespaces'].find({})
MONGODB (6ms) recipes_development['recipes'].find({})
MONGODB (0ms) recipes_development['system.namespaces'].find({})
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48469d4064241d860002d9')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48469d4064241d8600032a')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48469a4064241d8600008d')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48469c4064241d86000273')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48469d4064241d86000365')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f4846a34064241d86000910')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48499a4064241c58000027')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48499a4064241c58000027')}).limit(-1).sort([[:created_at, :desc]])
MONGODB (0ms) recipes_development['users'].find({:_id=>BSON::ObjectId('4f48499a4064241c58000027')}).limit(-1).sort([[:created_at, :desc]])
... many more ...
これをより効率的にするにはどうすればよいですか、または私が典型的に見ている動作ですか?
は、だから私はこれらのレコードを取得しています方法は、これらのスコープ経由でアップデート:私は以下のようなものを私のコントローラでインスタンスvaribaleを設定すると
scope :active, where(:active => true)
default_scope order_by([:created_at, :desc])
:
@users = User.active
Mongoidでどのようなコマンドを使用すると、これらすべてを取得するために発行されていますユーザーですか? –
ねえ、ジェシー、私は私の質問を更新した、私は最初の場所でそれを含めるべきだったね?ご協力ありがとうございます! –
これは、古典的なn + 1の問題のように見えます...あなたは、すべてのレシピを見ているわけではないと確信していますか? –