From 1150ab80a01a40151062697582976ddfaf89727c Mon Sep 17 00:00:00 2001 From: Wei-Meng Lee Date: Tue, 16 Apr 2019 23:39:56 +0800 Subject: [PATCH] Abstract author into private method --- app/finders/autocomplete/users_finder.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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.