Commit f0e07c6b authored by Dylan Griffith's avatar Dylan Griffith

Optimize IssuesFinder redundent confidential check when assigned

This query is sub-optimal and is frequently reported in the top 15 in
total time taken due to the fact that this is used to count the number
of assigned open issues on header bar which is loaded on every page
load.

Since a common use case is filtering by assigned to self (ie. the count
of assigned issues) we can optimize this query by not bothering to check
for confidentiality as it doesn't affect the outcome as you can see
assigned issues regardless of confidentiality.
parent 7912ce21
......@@ -47,6 +47,15 @@ class IssuesFinder < IssuableFinder
# rubocop: disable CodeReuse/ActiveRecord
def with_confidentiality_access_check
return Issue.all if params.user_can_see_all_confidential_issues?
if Feature.enabled?(:optimize_issue_filter_assigned_to_self, default_enabled: :yaml)
# If already filtering by assignee we can skip confidentiality since a user
# can always see confidential issues assigned to them. This is just an
# optimization since a very common usecase of this Finder is to load the
# count of issues assigned to the user for the header bar.
return Issue.all if current_user && params.assignees.include?(current_user)
end
return Issue.where('issues.confidential IS NOT TRUE') if params.user_cannot_see_confidential_issues?
Issue.where('
......
---
title: Optimize database performance of loading assigned issue count on header bar
merge_request: 57073
author:
type: performance
---
name: optimize_issue_filter_assigned_to_self
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57073
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/325470
milestone: '13.11'
type: development
group: group::global search
default_enabled: false
# frozen_string_literal: true
RSpec.shared_examples 'assignee ID filter' do
context 'when optimize_issue_filter_assigned_to_self is disabled' do
before do
stub_feature_flags(optimize_issue_filter_assigned_to_self: false)
end
it 'returns issuables assigned to that user' do
expect(issuables).to contain_exactly(*expected_issuables)
end
end
it 'returns issuables assigned to that user' do
expect(issuables).to contain_exactly(*expected_issuables)
end
......@@ -13,6 +23,16 @@ RSpec.shared_examples 'assignee NOT ID filter' do
end
RSpec.shared_examples 'assignee username filter' do
context 'when optimize_issue_filter_assigned_to_self is disabled' do
before do
stub_feature_flags(optimize_issue_filter_assigned_to_self: false)
end
it 'returns issuables assigned to those users' do
expect(issuables).to contain_exactly(*expected_issuables)
end
end
it 'returns issuables assigned to those users' do
expect(issuables).to contain_exactly(*expected_issuables)
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