Use Elasticsearch for autocomplete_sources/members
Implement backend changes required to make Issue and MR notes use Elasticsearch search-as-you-type
.
Context
Issue and MR note @mentions are notoriously slow when searching for a user for /assign
, /assign_reviewer
, /cc
, etc. An initial load makes an API call to fetch all possible users and store them in cache for subsequent searches. For the gitlab project, a few thousand users are returned and cached making the initial call take 3.37
seconds to receive a response from the backend.
We want to move to using Elasticsearch to provide autocomplete results for users. The first feature we want to change is @mentions on Issue and MR notes but this could be extended to other features as well.
#388197 is the frontend part of this backend issue.
Implementation
Make use of the User index and Elasticsearch search-as-you-type to provide a more responsive autosuggest experience on Issue and MR notes.
Requirements:
-
Changes are behind a feature flag autosuggest-users-using-elasticsearch
and guarded byElastic::DataMigrationService.migration_has_finished?
forcreate_user_index
andbackfill_users
. -
Implement a way to make an elasticsearch call to fetch matching users when use_elasticsearch?
istrue
. -
Update the mappings of username
andname
to allow for search-as-you-type. -
Return users that match the term AND are one of: -
The note owner -
A participant of the note -
A member of the project: get this as part of the Elasticsearch query using namespace_ancestry_ids
since the database query for this takes 0.5 seconds. -
@all
or one ofcurrent_user.authorized_groups
: for the first iteration this could be done as a separate step using database calls and future iterations could see these options added to elasticsearch.
-
-
If possible, use the busy
field from elasticsearch to remove the need for lazy loading availability -
Sorting: The owner and participants of the note are shown at the top, then users, then @all
and groups