Commit 4b8f33fe authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Utilize `ProjectSetting#has_vulnerabilities` attribute to get projects

Previous query was joining to `vulnerabilities` table which was causing
timeout errors.
parent e0c43662
......@@ -149,7 +149,7 @@ module EE
scope :with_designs, -> { where(id: ::DesignManagement::Design.select(:project_id).distinct) }
scope :with_deleting_user, -> { includes(:deleting_user) }
scope :with_compliance_framework_settings, -> { preload(:compliance_framework_setting) }
scope :has_vulnerabilities, -> { joins(:vulnerabilities).group(:id) }
scope :has_vulnerabilities, -> { joins(:project_setting).merge(::ProjectSetting.has_vulnerabilities) }
scope :has_vulnerability_statistics, -> { joins(:vulnerability_statistic) }
scope :with_vulnerability_statistics, -> { includes(:vulnerability_statistic) }
......
......@@ -6,6 +6,8 @@ module EE
prepended do
belongs_to :push_rule
scope :has_vulnerabilities, -> { where('has_vulnerabilities IS TRUE') }
end
end
end
# frozen_string_literal: true
FactoryBot.modify do
factory :project_setting do
trait :has_vulnerabilities do
has_vulnerabilities { true }
end
end
end
......@@ -15,7 +15,8 @@ RSpec.describe Resolvers::NamespaceProjectsResolver do
before do
project_1.add_developer(current_user)
project_2.add_developer(current_user)
create(:vulnerability, project: project_1)
project_1.project_setting.update!(has_vulnerabilities: true)
end
describe '#resolve' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProjectSetting do
it { is_expected.to belong_to(:push_rule) }
describe '.has_vulnerabilities' do
let_it_be(:setting_1) { create(:project_setting, :has_vulnerabilities) }
let_it_be(:setting_2) { create(:project_setting) }
subject { described_class.has_vulnerabilities }
it { is_expected.to contain_exactly(setting_1) }
end
end
......@@ -248,9 +248,11 @@ RSpec.describe Project do
describe '.has_vulnerabilities' do
let_it_be(:project_1) { create(:project) }
let_it_be(:project_2) { create(:project) }
let_it_be(:project_3) { create(:project) }
before do
create(:vulnerability, project: project_1)
project_1.project_setting.update!(has_vulnerabilities: true)
project_2.project_setting.update!(has_vulnerabilities: false)
end
subject { described_class.has_vulnerabilities }
......
......@@ -10,8 +10,8 @@ RSpec.describe Vulnerabilities::Statistics::ScheduleWorker do
let(:deleted_project) { create(:project, pending_delete: true) }
before do
create(:vulnerability, project: project)
create(:vulnerability, project: deleted_project)
project.project_setting.update!(has_vulnerabilities: true)
deleted_project.project_setting.update!(has_vulnerabilities: true)
allow(Vulnerabilities::Statistics::AdjustmentWorker).to receive(:perform_in)
end
......
# frozen_string_literal: true
FactoryBot.define do
factory :project_setting do
project
end
end
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