Commit cd656246 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '230712-fix-n-1-queries-for-issues-search' into 'master'

Fix N+1 queries for issues search

See merge request gitlab-org/gitlab!58915
parents 32b59545 97ba8a76
...@@ -114,7 +114,7 @@ class Issue < ApplicationRecord ...@@ -114,7 +114,7 @@ class Issue < ApplicationRecord
scope :order_severity_desc, -> { includes(:issuable_severity).order('issuable_severities.severity DESC NULLS LAST') } scope :order_severity_desc, -> { includes(:issuable_severity).order('issuable_severities.severity DESC NULLS LAST') }
scope :preload_associated_models, -> { preload(:assignees, :labels, project: :namespace) } scope :preload_associated_models, -> { preload(:assignees, :labels, project: :namespace) }
scope :with_web_entity_associations, -> { preload(:author, :project) } scope :with_web_entity_associations, -> { preload(:author, project: [:project_feature, :route, namespace: :route]) }
scope :with_label_attributes, ->(label_attributes) { joins(:labels).where(labels: label_attributes) } scope :with_label_attributes, ->(label_attributes) { joins(:labels).where(labels: label_attributes) }
scope :with_alert_management_alerts, -> { joins(:alert_management_alert) } scope :with_alert_management_alerts, -> { joins(:alert_management_alert) }
scope :with_prometheus_alert_events, -> { joins(:issues_prometheus_alert_events) } scope :with_prometheus_alert_events, -> { joins(:issues_prometheus_alert_events) }
......
---
title: Fix N+1 queries for issues search
merge_request: 58915
author:
type: performance
...@@ -45,9 +45,7 @@ RSpec.describe 'Global elastic search', :elastic, :sidekiq_inline do ...@@ -45,9 +45,7 @@ RSpec.describe 'Global elastic search', :elastic, :sidekiq_inline do
let(:object) { :issue } let(:object) { :issue }
let(:creation_args) { { project: project, title: 'initial' } } let(:creation_args) { { project: project, title: 'initial' } }
let(:path) { search_path(search: 'initial', scope: 'issues') } let(:path) { search_path(search: 'initial', scope: 'issues') }
# N+1 queries still exist and will be fixed per let(:query_count_multiplier) { 0 }
# https://gitlab.com/gitlab-org/gitlab/-/issues/230712
let(:query_count_multiplier) { 1 }
it_behaves_like 'an efficient database result' it_behaves_like 'an efficient database result'
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