Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1850

identity map is never consulted by multi-id finders

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      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)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            ghost Deleted user
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: