Fix join between ci_job_token_project_scope_links and projects
Described in gitlab-org/manage/general-discussion#17363 (comment 622734759). The join between ci_job_token and projects will be broken by the decomposed databases.
Proposal
Break the query in 2 separate ones:
diff --git a/app/models/ci/job_token/scope.rb b/app/models/ci/job_token/scope.rb
index 42cfdc21d66..1ad70fccdce 100644
--- a/app/models/ci/job_token/scope.rb
+++ b/app/models/ci/job_token/scope.rb
@@ -32,12 +32,17 @@ def includes?(target_project)
def all_projects
Project.from_union([
Project.id_in(source_project),
- Project.where_exists(
- Ci::JobToken::ProjectScopeLink
- .from_project(source_project)
- .where('projects.id = ci_job_token_project_scope_links.target_project_id'))
+ Project.id_in(target_project_ids)
], remove_duplicates: false)
end
+
+ private
+
+ def target_project_ids
+ Ci::JobToken::ProjectScopeLink
+ .from_project(source_project)
+ .pluck(:target_project_id)
+ end
end
end
end
Ci::JobToken::Scope#all_projects
is only used when managing the job token scope in the project settings. We don't expect a huge number of projects being returned at the moment since it will be used to list private projects requiring access from a given project.
Edited by Fabio Pitino