Cache user project authorizations for faster autocomplete and search

What does this MR do and why?

Adds a search cache concern which starts with one method: yield_with_cache which can be run with a block to cache a single value or array.

The first application is for caching Global Search projects list for a user when advanced search is enabled. Computing projects for a user is expensive and if we compute it once and cache it for one minute, any subsequent calls within a minute will be much quicker. This would help projects autocomplete (when advanced search is enabled) a lot since we make calls for every character entered and now it can be quickly searched; this will also help Advanced Global Search.

The feature is behind a feature flag: [Feature flag] Rollout of `search_cache_authori... (#499721 - closed)

What can go wrong?

Since the user's authorized projects are cached, search results might be out of date if their authorized projects change within the cache time (1 minute).

  • If the user loses access to a project in that time: the redaction logic will catch it so that the user does not see search results they don't have access to
  • If the user gains access to a project in that time: they will not see search results for that project until the cache expires

Future work

  • Work on expiring the cache when a user's authorized projects change so that we can cache for longer.
  • Apply similar caching for other searches:
    • Other autocomplete scopes
    • Basic search

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Enable using search service for project autocomplete: Feature.enable(:autocomplete_projects_use_search_service)
  2. Disable the feature flag: Feature.disable(:search_cache_authorizations)
  3. Do an autocomplete
  4. Do some global and group searches
  5. Enable the feature flag: Feature.enable(:search_cache_authorizations)
  6. Do an autocomplete and see that the results are the same. Locally the execution time might not be much different
  7. Do some global and group searches and see the results

Related to #472011 (closed)

Edited by Madelein van Niekerk

Merge request reports

Loading