diff options
| author | Louise Crow <louise.crow@gmail.com> | 2014-12-18 09:18:16 +0000 | 
|---|---|---|
| committer | Louise Crow <louise.crow@gmail.com> | 2014-12-18 09:18:16 +0000 | 
| commit | a21420efff11968c58c9d220ea5f9974142056b6 (patch) | |
| tree | 33afe4de89ed7bfc9fc7a990bff27d3f4fbbd488 | |
| parent | 7414ed478f212be2b48c95fafde15726b348b197 (diff) | |
Try to avoid n+1 queries, and multiple admin authority queries.0.20.0.1hotfix/0.20.0.1
Attempting to make the import faster when there are lots of public authorities in the database already
| -rw-r--r-- | app/models/public_body.rb | 5 | 
1 files changed, 3 insertions, 2 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 1929272ea..a9cdfeab2 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -454,11 +454,12 @@ class PublicBody < ActiveRecord::Base                  # of updating them                  bodies_by_name = {}                  set_of_existing = Set.new() +                internal_admin_body_id = PublicBody.internal_admin_body.id                  I18n.with_locale(I18n.default_locale) do -                    bodies = (tag.nil? || tag.empty?) ? PublicBody.find(:all) : PublicBody.find_by_tag(tag) +                    bodies = (tag.nil? || tag.empty?) ? PublicBody.find(:all, :include => :translations) : PublicBody.find_by_tag(tag)                      for existing_body in bodies                          # Hide InternalAdminBody from import notes -                        next if existing_body.id == PublicBody.internal_admin_body.id +                        next if existing_body.id == internal_admin_body_id                          bodies_by_name[existing_body.name] = existing_body                          set_of_existing.add(existing_body.name)  | 
