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

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
28
# 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]
  @author_id = params[:author_id]
  @todo_filter = params[:todo_filter]
  @todo_state_filter = params[:todo_state_filter]
  @filter_by_current_user = params[:current_user]
  @states = params[:states] || ['active']
  @push_code = params[:push_code]
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

#push_codeObject (readonly)

Returns the value of attribute push_code.



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

def push_code
  @push_code
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

#statesObject (readonly)

Returns the value of attribute states.



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

def states
  @states
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



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

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?

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

  items = filter_users_by_push_ability(items)

  items.uniq.tap do |unique_items|
    preload_associations(unique_items)
  end
end