Commit d8ab5ab7 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'remove-joins-in-job-token-scope' into 'master'

Remove cross-database joins in job token scope code

See merge request gitlab-org/gitlab!70191
parents d20ba0b5 81c759fb
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
module Ci module Ci
module JobToken module JobToken
class ProjectScopeLink < ApplicationRecord class ProjectScopeLink < Ci::ApplicationRecord
self.table_name = 'ci_job_token_project_scope_links' self.table_name = 'ci_job_token_project_scope_links'
belongs_to :source_project, class_name: 'Project' belongs_to :source_project, class_name: 'Project'
......
...@@ -32,12 +32,15 @@ module Ci ...@@ -32,12 +32,15 @@ module Ci
def all_projects def all_projects
Project.from_union([ Project.from_union([
Project.id_in(source_project), Project.id_in(source_project),
Project.where_exists( Project.id_in(target_project_ids)
Ci::JobToken::ProjectScopeLink
.from_project(source_project)
.where('projects.id = ci_job_token_project_scope_links.target_project_id'))
], remove_duplicates: false) ], remove_duplicates: false)
end end
private
def target_project_ids
Ci::JobToken::ProjectScopeLink.from_project(source_project).pluck(:target_project_id)
end
end end
end end
end end
...@@ -121,7 +121,6 @@ ...@@ -121,7 +121,6 @@
- "./spec/migrations/schedule_migrate_security_scans_spec.rb" - "./spec/migrations/schedule_migrate_security_scans_spec.rb"
- "./spec/models/ci/build_spec.rb" - "./spec/models/ci/build_spec.rb"
- "./spec/models/ci/job_artifact_spec.rb" - "./spec/models/ci/job_artifact_spec.rb"
- "./spec/models/ci/job_token/scope_spec.rb"
- "./spec/models/ci/pipeline_spec.rb" - "./spec/models/ci/pipeline_spec.rb"
- "./spec/models/ci/runner_spec.rb" - "./spec/models/ci/runner_spec.rb"
- "./spec/models/clusters/applications/runner_spec.rb" - "./spec/models/clusters/applications/runner_spec.rb"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment