summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorWei-Meng Lee <wlee@gitlab.com>2019-04-16 23:39:56 +0800
committerWei-Meng Lee <wlee@gitlab.com>2019-04-16 23:39:56 +0800
commit1150ab80a01a40151062697582976ddfaf89727c (patch)
tree949d12c3a1bb096b4133a877c2bda626561ee207 /app/finders
parent3ef5666783b220422283e4d5acbcbbbfac1e935a (diff)
downloadgitlab-ce-1150ab80a01a40151062697582976ddfaf89727c.tar.gz
Abstract author into private methodweimeng-user-autocomplete-fix
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/autocomplete/users_finder.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/app/finders/autocomplete/users_finder.rb b/app/finders/autocomplete/users_finder.rb
index 9df77dbdc0f..ce7d0b8699c 100644
--- a/app/finders/autocomplete/users_finder.rb
+++ b/app/finders/autocomplete/users_finder.rb
@@ -2,6 +2,8 @@
module Autocomplete
class UsersFinder
+ include Gitlab::Utils::StrongMemoize
+
# The number of users to display in the results is hardcoded to 20, and
# pagination is not supported. This ensures that performance remains
# consistent and removes the need for implementing keyset pagination to
@@ -31,7 +33,7 @@ module Autocomplete
# Include current user if available to filter by "Me"
items.unshift(current_user) if prepend_current_user?
- if (prepend_author? && author = User.find_by_id(author_id)) && author.active?
+ if prepend_author? && author&.active?
items.unshift(author)
end
end
@@ -41,6 +43,12 @@ module Autocomplete
private
+ def author
+ strong_memoize(:author) do
+ User.find_by_id(author_id)
+ end
+ end
+
# Returns the users based on the input parameters, as an Array.
#
# This method is separate so it is easier to extend in EE.