Commit 6b119359 authored by Jan Provaznik's avatar Jan Provaznik

Make sure that CI jobs are preloaded

Because artifact's job is now used also when rendering
pipeline jobs (if merge_request_cached_pipeline_serializer flag is
enabled), we should preload jobs independently on non_public_artifacts
flag enablement.
parent 48e6b011
......@@ -136,11 +136,7 @@ module Ci
scope :for_sha, ->(sha, project_id) { joins(job: :pipeline).where(ci_pipelines: { sha: sha, project_id: project_id }) }
scope :for_job_name, ->(name) { joins(:job).where(ci_builds: { name: name }) }
scope :with_job, -> do
if Feature.enabled?(:non_public_artifacts, type: :development)
joins(:job).includes(:job)
end
end
scope :with_job, -> { joins(:job).includes(:job) }
scope :with_file_types, -> (file_types) do
types = self.file_types.select { |file_type| file_types.include?(file_type) }.values
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'merge request content spec' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:merge_request) { create(:merge_request, :with_head_pipeline, target_project: project, source_project: project) }
let_it_be(:ci_build) { create(:ci_build, :artifacts, pipeline: merge_request.head_pipeline) }
before do
sign_in(user)
project.add_maintainer(user)
end
shared_examples 'cached widget request' do
it 'avoids N+1 queries when multiple job artifacts are present' do
control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
get cached_widget_project_json_merge_request_path(project, merge_request, format: :json)
end
create_list(:ci_build, 10, :artifacts, pipeline: merge_request.head_pipeline)
expect do
get cached_widget_project_json_merge_request_path(project, merge_request, format: :json)
end.not_to exceed_query_limit(control)
end
end
describe 'GET cached_widget' do
it_behaves_like 'cached widget request'
context 'with non_public_artifacts disabled' do
before do
stub_feature_flags(non_public_artifacts: false)
end
it_behaves_like 'cached widget request'
end
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