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

'includes' doesn't use IdentityMap

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Resolution: Done
    • None
    • 3.1.0
    • None
    • None

    Description

      I think, that whenever you use 'includes', there should be only performance difference, but not functional difference. But here's what I get:

      >> CityRoute.includes(:orig).first
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=city_routes selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.6924ms)
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=places selector={"deleted_at"=>nil, "_id"=>

      {"$in"=>["4eda5f2e8792904be40001b7"]}, "_type"=>{"$in"=>["City"]}} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.7296ms)
      #<CityRoute _id: 50d85fcbbdaa57462e000002 ... >
      >> CityRoute.includes(:orig).first
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=city_routes selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.6459ms)
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=places selector={"deleted_at"=>nil, "_id"=>{"$in"=>["4eda5f2e8792904be40001b7"]}

      , "_type"=>{"$in"=>["City"]}} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.5293ms)
      #<CityRoute _id: 50d85fcbbdaa57462e000002 ... >
      >> CityRoute.first.orig
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=city_routes selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.8597ms)
      #<City _id: 4eda5f2e8792904be40001b7 ... >

      So 'includes' doesn't use IdentityMap to get all or part of required records. So if I don't use 'includes', I get old records stored in ItentityMap, but if I use 'includes', the records are requested again and possibly they've already been changed (so that's the functional difference). Also, of course, to get the records from IdentityMap would be more efficient in terms of performance. Especially the difference is noticeable when you make something like '.includes(:orig, :dest)', when both the relations reference the same collection and included ids are nearly the same. This way the same set of records is requested twice in a row.

      Attachments

        Activity

          People

            Unassigned Unassigned
            exoth Yuriy Trofimenko
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: