Skip to content

Prevent 2nd Elasticsearch query for project searches

What does this MR do?

We memoize the result object so that when it is later evaluated the same Elasticsearch result can be used for the total_count.

We also extract a shared test examples for the 3 different kinds of Elastic search results to reduce the chance of regression here.

This memoize approach to solving this problem was originally introduced in !13120 (merged)

Note that some of the methods being memoized have arguments and as such the memoization is not logically consistent from the code perspective. We must memoize the results without the page argument because #commits_count,#blobs_count,#wiki_blobs_count don't have any inkling of the current page we're on - if we were to memoize with dynamic parameters we would end up hitting ES twice for any page that's not page 1, and that's something we want to avoid. It is safe to memoize the page we get here because the method is always called before the equivalent #_count method.

Read more at #219209 (closed)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

#219209 (closed)

Edited by Dylan Griffith

Merge request reports