Commit 8b3f42f9 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'id-n-1-for-milestone-issues' into 'master'

Remove N + 1 for milestones issues

See merge request gitlab-org/gitlab!57349
parents 57d2b83a 4fcf4177
......@@ -115,7 +115,6 @@ class Issue < ApplicationRecord
scope :preload_associated_models, -> { preload(:assignees, :labels, project: :namespace) }
scope :with_web_entity_associations, -> { preload(:author, :project) }
scope :with_api_entity_associations, -> { preload(:timelogs, :assignees, :author, :notes, :labels, project: [:route, { namespace: :route }] ) }
scope :with_label_attributes, ->(label_attributes) { joins(:labels).where(labels: label_attributes) }
scope :with_alert_management_alerts, -> { joins(:alert_management_alert) }
scope :with_prometheus_alert_events, -> { joins(:issues_prometheus_alert_events) }
......
---
title: Remove N + 1 for milestones issues
merge_request: 57349
author:
type: performance
......@@ -80,7 +80,7 @@ module API
params = build_finder_params(milestone, parent)
issuables = finder_klass.new(current_user, params).execute
issuables = finder_klass.new(current_user, params).execute.with_api_entity_associations
present paginate(issuables), with: entity, current_user: current_user
end
......
......@@ -64,6 +64,24 @@ RSpec.describe API::GroupMilestones do
end
end
describe 'GET /groups/:id/milestones/:milestone_id/issues' do
let!(:issue) { create(:issue, project: project, milestone: milestone) }
def perform_request
get api("/groups/#{group.id}/milestones/#{milestone.id}/issues", user)
end
it 'returns multiple issues without performing N + 1' do
perform_request
control_count = ActiveRecord::QueryRecorder.new { perform_request }.count
create(:issue, project: project, milestone: milestone)
expect { perform_request }.not_to exceed_query_limit(control_count)
end
end
def setup_for_group
context_group.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
context_group.add_developer(user)
......
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