aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-05-14 09:57:17 +0100
committerGareth Rees <gareth@mysociety.org>2015-06-04 13:51:03 +0100
commitc63fcadb78b52e1ea0fb8410a9f1715d49671676 (patch)
tree6f0f9b95cda869cce4f6cc71fdc646a5ea3dbb83
parentdb759ed1f70efdf829ec1a581007aed883a86330 (diff)
Use SQL to find first result
No point loading all results if we're only ever going to return the first.
-rw-r--r--app/models/public_body.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 6b512da36..5053523a3 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -160,14 +160,14 @@ class PublicBody < ActiveRecord::Base
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
+ # If many bodies are found (usually because the url_name is the same
+ # across locales) return any of them.
found = joins(:translations).
where("public_body_translations.url_name = ?", name).
readonly(false).
- all
+ first
- # If many bodies are found (usually because the url_name is the same across
- # locales) return any of them
- return found.first if found.size >= 1
+ return found if found
# If none found, then search the history of short names and find unique
# public bodies in it