Class: Autocomplete::UsersFinder

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/finders/autocomplete/users_finder.rb

Constant Summary collapse

LIMIT =

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 ensure good performance.

20

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(params:, current_user:, project:, group:) ⇒ UsersFinder

Returns a new instance of UsersFinder.


17
18
19
20
21
22
23
24
25
26
27
# File 'app/finders/autocomplete/users_finder.rb', line 17

def initialize(params:, current_user:, project:, group:)
  @current_user = current_user
  @project = project
  @group = group
  @search = params[:search]
  @skip_users = params[:skip_users]
  @author_id = params[:author_id]
  @todo_filter = params[:todo_filter]
  @todo_state_filter = params[:todo_state_filter]
  @filter_by_current_user = params[:current_user]
end

Instance Attribute Details

#author_idObject (readonly)

Returns the value of attribute author_id


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def author_id
  @author_id
end

#current_userObject (readonly)

Returns the value of attribute current_user


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def current_user
  @current_user
end

#filter_by_current_userObject (readonly)

Returns the value of attribute filter_by_current_user


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def filter_by_current_user
  @filter_by_current_user
end

#groupObject (readonly)

Returns the value of attribute group


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def group
  @group
end

#projectObject (readonly)

Returns the value of attribute project


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def project
  @project
end

#searchObject (readonly)

Returns the value of attribute search


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def search
  @search
end

#skip_usersObject (readonly)

Returns the value of attribute skip_users


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def skip_users
  @skip_users
end

#todo_filterObject (readonly)

Returns the value of attribute todo_filter


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def todo_filter
  @todo_filter
end

#todo_state_filterObject (readonly)

Returns the value of attribute todo_state_filter


13
14
15
# File 'app/finders/autocomplete/users_finder.rb', line 13

def todo_state_filter
  @todo_state_filter
end

Instance Method Details

#executeObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/finders/autocomplete/users_finder.rb', line 29

def execute
  items = limited_users

  if search.blank?
    # Include current user if available to filter by "Me"
    items.unshift(current_user) if prepend_current_user?

    if prepend_author? && author&.active?
      items.unshift(author)
    end
  end

  items.uniq
end