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

QueryCache is only working when loading only one document

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 4.0.0 final
    • Component/s: None
    • Labels:

      Description

      See Orignal thread on Google Groups.

      For example the following code :

      Mongoid::QueryCache.enabled? # returns true
      u = Media.last.owner
      u.medias.last.owner
      u.medias.last.owner
      Mongoid::QueryCache.cache_table # returns {}
      

      produces the following queries :

      D, [2014-01-30T18:45:40.281417 #22461]
       DEBUG -- :   MOPED: 192.168.122.54:27017 QUERY        database=wisdom_development collection=medias selector={"$query"=>{"client_id"=>BSON::ObjectId('50bf85634efbbe9721000001')}, "$orderby"=>{:_id=>-1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.8730ms
       
      D, [2014-01-30T18:45:40.282639 #22461] DEBUG -- :   MOPED: 192.168.122.54:27017 QUERY        database=wisdom_development collection=users selector={"$query"=>{"client_id"=>BSON::ObjectId('50bf85634efbbe9721000001'), "deleted_at"=>nil, "_id"=>BSON::ObjectId('50c7540d4efbbe23f9000007')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4608ms
       
      D, [2014-01-30T18:45:40.284591 #22461] DEBUG -- :   MOPED: 192.168.122.54:27017 QUERY        database=wisdom_development collection=medias selector={"$query"=>{"client_id"=>BSON::ObjectId('50bf85634efbbe9721000001'), "owner_id"=>BSON::ObjectId('50c7540d4efbbe23f9000007')}, "$orderby"=>{:_id=>-1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.6127ms
       
      D, [2014-01-30T18:45:40.285420 #22461] DEBUG -- :   MOPED: 192.168.122.54:27017 QUERY        database=wisdom_development collection=medias selector={"$query"=>{"client_id"=>BSON::ObjectId('50bf85634efbbe9721000001'), "owner_id"=>BSON::ObjectId('50c7540d4efbbe23f9000007')}, "$orderby"=>{:_id=>-1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.5771ms
      

      The last 2 queries are exactly the same. FYI the client_id condition is due to a default scope (from the gem mongoid_multitenancy).

      The problem is the query cache is only working when loading more than one document.

      For calls like these, ie #last or #first it's not hitting the cache. You can see it proxies #load_docs but doesn't also proxy#first on Moped's query object

        Attachments

          Activity

            People

            Assignee:
            durran Durran Jordan
            Reporter:
            abrisse abrisse
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: