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
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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