Abstract author into private method

This commit is contained in:
Wei-Meng Lee 2019-04-16 23:39:56 +08:00
parent 3ef5666783
commit 1150ab80a0

View file

@ -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.