Prevent 2nd Elasticsearch query for project searches
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 https://gitlab.com/gitlab-org/gitlab/-/merge_requests/13120 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 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 https://gitlab.com/gitlab-org/gitlab/-/issues/219209
Showing
Please register or sign in to comment