From 16c9a2f4691de519e7f1c4aefbd358d9086bb4d3 Mon Sep 17 00:00:00 2001
From: Thong Kuah <tkuah@gitlab.com>
Date: Thu, 2 Sep 2021 21:48:32 +1200
Subject: [PATCH] Allow callsite in project for cross-database queries

This callsite allow replaces at least one spec allowlist. This callsite
is called ~800 times in our CI for cross-database queries so it likely
affects more than just this one spec.
---
 app/models/project.rb                          | 10 ++++------
 spec/support/database/cross-join-allowlist.yml |  1 -
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/app/models/project.rb b/app/models/project.rb
index 6d4d25695dfbee..9410dfaef27a0e 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1789,7 +1789,9 @@ def active_runners
   end
 
   def any_online_runners?(&block)
-    online_runners_with_tags.any?(&block)
+    ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/339937') do
+      online_runners_with_tags.any?(&block)
+    end
   end
 
   def valid_runners_token?(token)
@@ -2895,12 +2897,8 @@ def cache_has_external_issue_tracker
     update_column(:has_external_issue_tracker, integrations.external_issue_trackers.any?) if Gitlab::Database.read_write?
   end
 
-  def active_runners_with_tags
-    @active_runners_with_tags ||= active_runners.with_tags
-  end
-
   def online_runners_with_tags
-    @online_runners_with_tags ||= active_runners_with_tags.online
+    @online_runners_with_tags ||= active_runners.with_tags.online
   end
 end
 
diff --git a/spec/support/database/cross-join-allowlist.yml b/spec/support/database/cross-join-allowlist.yml
index 5411cbce46f71f..bed2537e2a4490 100644
--- a/spec/support/database/cross-join-allowlist.yml
+++ b/spec/support/database/cross-join-allowlist.yml
@@ -77,7 +77,6 @@
 - "./ee/spec/requests/api/vulnerability_findings_spec.rb"
 - "./ee/spec/serializers/dashboard_environment_entity_spec.rb"
 - "./ee/spec/serializers/dashboard_environments_serializer_spec.rb"
-- "./ee/spec/serializers/dashboard_operations_project_entity_spec.rb"
 - "./ee/spec/serializers/ee/build_details_entity_spec.rb"
 - "./ee/spec/serializers/merge_request_poll_widget_entity_spec.rb"
 - "./ee/spec/services/auto_merge/add_to_merge_train_when_pipeline_succeeds_service_spec.rb"
-- 
GitLab