From 695d4ed8b2ae25537e47e5f4ad38d05a8d528582 Mon Sep 17 00:00:00 2001
From: Arturo Herrero <arturo.herrero@gmail.com>
Date: Mon, 22 Jul 2024 12:49:01 +0200
Subject: [PATCH] Fix Rubocop errors for elastic search results

---
 .rubocop_todo/gitlab/strong_memoize_attr.yml |  1 -
 .rubocop_todo/lint/symbol_conversion.yml     |  1 -
 ee/lib/gitlab/elastic/search_results.rb      | 16 ++++++++--------
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/.rubocop_todo/gitlab/strong_memoize_attr.yml b/.rubocop_todo/gitlab/strong_memoize_attr.yml
index 7435d43a2d362..06b7d974b432f 100644
--- a/.rubocop_todo/gitlab/strong_memoize_attr.yml
+++ b/.rubocop_todo/gitlab/strong_memoize_attr.yml
@@ -405,7 +405,6 @@ Gitlab/StrongMemoizeAttr:
     - 'ee/lib/gitlab/elastic/document_reference.rb'
     - 'ee/lib/gitlab/elastic/indexer.rb'
     - 'ee/lib/gitlab/elastic/project_search_results.rb'
-    - 'ee/lib/gitlab/elastic/search_results.rb'
     - 'ee/lib/gitlab/expiring_subscription_message.rb'
     - 'ee/lib/gitlab/geo/health_check.rb'
     - 'ee/lib/gitlab/geo/jwt_request_decoder.rb'
diff --git a/.rubocop_todo/lint/symbol_conversion.yml b/.rubocop_todo/lint/symbol_conversion.yml
index 927e9d1688b22..b13174918d8f5 100644
--- a/.rubocop_todo/lint/symbol_conversion.yml
+++ b/.rubocop_todo/lint/symbol_conversion.yml
@@ -46,7 +46,6 @@ Lint/SymbolConversion:
     - 'ee/app/workers/security/store_scans_worker.rb'
     - 'ee/lib/api/concerns/dependency_proxy/packages_helpers.rb'
     - 'ee/lib/ee/api/helpers.rb'
-    - 'ee/lib/gitlab/elastic/search_results.rb'
     - 'ee/lib/gitlab/geo/replicator.rb'
     - 'ee/lib/gitlab/graphql/aggregations/epics/epic_node.rb'
     - 'ee/lib/search/zoekt/search_results.rb'
diff --git a/ee/lib/gitlab/elastic/search_results.rb b/ee/lib/gitlab/elastic/search_results.rb
index d11bfed2ab6f7..81343ec9f238e 100644
--- a/ee/lib/gitlab/elastic/search_results.rb
+++ b/ee/lib/gitlab/elastic/search_results.rb
@@ -17,7 +17,9 @@ class SearchResults
       # It allows us to search only for projects user has access to
       attr_reader :limit_project_ids
 
-      def initialize(current_user, query, limit_project_ids = nil, root_ancestor_ids: nil, public_and_internal_projects: true, order_by: nil, sort: nil, filters: {})
+      def initialize(
+        current_user, query, limit_project_ids = nil, root_ancestor_ids: nil,
+        public_and_internal_projects: true, order_by: nil, sort: nil, filters: {})
         @current_user = current_user
         @query = query
         @limit_project_ids = limit_project_ids
@@ -40,7 +42,6 @@ def error(scope)
         issues.error
       end
 
-      # rubocop:disable Metrics/CyclomaticComplexity -- method consists of case statement only
       def objects(scope, page: 1, per_page: DEFAULT_PER_PAGE, preload_method: nil)
         page = (page || 1).to_i
 
@@ -75,7 +76,6 @@ def objects(scope, page: 1, per_page: DEFAULT_PER_PAGE, preload_method: nil)
           Kaminari.paginate_array([])
         end
       end
-      # rubocop:enable Metrics/CyclomaticComplexity
 
       # Pull the highlight attribute out of Elasticsearch results
       # and map it to the result id
@@ -327,7 +327,8 @@ def scope_options(scope)
           base_options.merge(filters.slice(:include_archived))
         when :merge_requests
           base_options
-            .merge(filters.slice(:order_by, :sort, :state, :include_archived, :source_branch, :not_source_branch, :author_username, :not_author_username))
+            .merge(filters.slice(:order_by, :sort, :state, :include_archived, :source_branch, :not_source_branch,
+              :author_username, :not_author_username))
         when :issues
           base_options.merge(
             filters.slice(:order_by, :sort, :confidential, :state, :labels, :label_name, :include_archived),
@@ -358,7 +359,7 @@ def scope_results(scope, klass, count_only:)
       end
 
       def memoize_key(scope, count_only:)
-        count_only ? "#{scope}_results_count".to_sym : scope
+        count_only ? :"#{scope}_results_count" : scope
       end
 
       def projects(count_only: false)
@@ -468,10 +469,9 @@ def elastic_search_limited_counter_with_delimiter(count)
       end
 
       def blob_aggregations
-        strong_memoize(:blob_aggregations) do
-          Repository.__elasticsearch__.blob_aggregations(query, base_options)
-        end
+        Repository.__elasticsearch__.blob_aggregations(query, base_options)
       end
+      strong_memoize_attr :blob_aggregations
 
       def issue_aggregations
         if Feature.disabled?(:search_issue_refactor, current_user)
-- 
GitLab