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

find_or_initialize_by in high volume

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • 6.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      Hi,
      we are importing a lot of small docs into. To avoid duplicates we use find_or_initialize_by with fields. Looking at the logs Mongoid has to make a query for each find_or_initialize_by call. This makes me wondering if there is a way to improve performance with Mongoid out of the box.

      I could think of not using find_or_initialize_by and instead preloading corresponding data and searching with ruby methods to check if the documents already exists. However I would be nice if Mongoid had some cache I could load before through which it would a first finding attempt before actually hitting the database server.

      Cheers,
      Martin

            Assignee:
            Unassigned Unassigned
            Reporter:
            martin_cp Martin Stemmle
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: