Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

identity map is never consulted by multi-id finders #1849

Closed
ghost opened this Issue · 1 comment

2 participants

Hans Hasselberg Durran Jordan
Deleted user

It seems like mongoid's Model.find command does not consult the identity map before querying the database for documents with IDs in a list. It correctly saves the resulting documents in the identity map, which is consulted before generating single-ID queries, but future multi-ID queries hit the database intact. I gather this is particularly impactful when Model.includes is used.

Below is a code sample that will reproduce the issue. Thanks!

require "rubygems"
require "mongoid"

Mongoid.configure do |config|
 config.master = Mongo::Connection.new('localhost', Mongo::Connection::DEFAULT_PORT, :logger => Logger.new(STDOUT)).db('test_db')
 config.identity_map_enabled = true
end

class TestDocument
  include Mongoid::Document
end

# clear the test document collection
TestDocument.collection.drop

# add two new documents
2.times { TestDocument.new.save }

# pull the ids
ids = TestDocument.all.distinct(:_id)


# run the test queries

logger.info "Group find."
TestDocument.find(ids)

logger.info "Single find."
TestDocument.find(ids.first)

logger.info "Same group find."
TestDocument.find(ids)
Hans Hasselberg

Hello @rcbth,

thanks for reporting. I can see what you mean and I'll have a look.

Durran Jordan durran closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.