From 843f4b94b59255ec27b3bdf22e93180fce74ddca Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Wed, 20 Feb 2019 11:31:06 +0000 Subject: Ignore ordering when calling find_by on finders We shouldn't care about the ordering here; if we did, it would be more appropriate to use `take` or `first`. Having the ordering can result in the database picking a bad query plan, as it might think sorting the whole table first is the best option. --- app/finders/concerns/finder_methods.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/finders') diff --git a/app/finders/concerns/finder_methods.rb b/app/finders/concerns/finder_methods.rb index 5290313585f..8de3276184d 100644 --- a/app/finders/concerns/finder_methods.rb +++ b/app/finders/concerns/finder_methods.rb @@ -3,13 +3,13 @@ module FinderMethods # rubocop: disable CodeReuse/ActiveRecord def find_by!(*args) - raise_not_found_unless_authorized execute.find_by!(*args) + raise_not_found_unless_authorized execute.reorder(nil).find_by!(*args) end # rubocop: enable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord def find_by(*args) - if_authorized execute.find_by(*args) + if_authorized execute.reorder(nil).find_by(*args) end # rubocop: enable CodeReuse/ActiveRecord -- cgit v1.2.3