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

Create does a slow query on every related object

    XMLWordPrintable

    Details

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

      Description

      Currently, when you do a create, it performs a query for all related (references_many) objects. This is really inefficient when those related collections are large.

      For example, if a User references_many :posts, x = User.create will call x.posts.all.each ...

      This happens in update_associations (here) where it calls:
      {{send(name).each

      { |doc| doc.save }

      if new_record?}}

      I believe that code is incorrect, and should say unless new_record? instead. Although, I'm not sure why you need to loop through every related object anyway.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: