[go: up one dir, main page]

Skip to content

Resolve cross-join in ProjectsGrades.grades_for with instance dashboard

Summary

The vulnerabilities/projects_grade.rb model has a scope to include projects which cannot be used when the tables are decomposed.

Further details

See https://gitlab.com/gitlab-org/gitlab/-/blob/5fa07731e2b22537958c4ebe3efba9a039a9a9e9/ee/app/models/vulnerabilities/projects_grade.rb#L31

    def self.grades_for(vulnerables, filter: nil, include_subgroups: false)
      projects = vulnerables.map do |v|
        collection = include_subgroups ? v.all_projects : v.projects
        collection.non_archived
      end

      relation = ::Vulnerabilities::Statistic.for_project(projects.reduce(&:or))
      relation = relation.by_grade(filter) if filter
      relation = relation.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/503387')

Proposal

2 options:

  • Move the users_security_dashboard_projects table to gitlab_sec. It then becomes possible to join it with vulnerability_statistics without causing a cross-database join. See !175602 (comment 2279123735)
  • Or, pluck the project IDs, and pass them to Vulnerabilities::Statistic.for_project.
implementation for moving users_security_dashboard_projects to gitlab_sec

See !175602 (comment 2279123735)

Verification

To be tested manually using the user/instance security dashboard page.

Edited by Fabien Catteau