• Dylan Griffith's avatar
    Prevent 2nd Elasticsearch query for project searches · 8541d5a9
    Dylan Griffith authored
    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
    8541d5a9
219209-remove-extra-elasticsearch-query-in-project-searches.yml 111 Bytes