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

Slow saves when many objects loaded in a relation

    XMLWordPrintable

    Details

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

      Description

      Tested on mongoid 3.1.6.

      >> foo = City.where(code:"ROV").first
      foo = City.where(code:"ROV").first
      #<City _id: 4eda5fb98792904be4001a6e, ...>

      >> Benchmark.measure

      { foo.save }
      0.010000 0.000000 0.010000 ( 0.011395)

      Now let's load some objects in a has_many relation (I intentionally do to_a to make them loaded):

      >> foo.city_routes.to_a.count
      1094

      >> Benchmark.measure { foo.save }

      10.810000 0.160000 10.970000 ( 11.404787)

      As you see, saves start to be very slow. Note, that autosave is false for this relation.

      Just tell me, if you need more information about the case.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: