Commit e1277411 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'fix-incorrect-issuable-counts' into 'master'

Fix incorrect issueable counts

See merge request gitlab-org/gitlab!61230
parents 8ea60725 d14031c2
......@@ -28,7 +28,6 @@ module OptimizedIssuableLabelFilter
# Taken from IssuableFinder
def count_by_state
return super if root_namespace.nil?
return super if Feature.disabled?(:optimized_issuable_label_filter, default_enabled: :yaml)
count_params = params.merge(state: nil, sort: nil, force_cte: true)
......@@ -40,7 +39,11 @@ module OptimizedIssuableLabelFilter
.group(:state_id)
.count
counts = state_counts.transform_keys { |key| count_key(key) }
counts = Hash.new(0)
state_counts.each do |key, value|
counts[count_key(key)] += value
end
counts[:all] = counts.values.sum
counts.with_indifferent_access
......
---
title: Fix incorrect issue and merge requests counts with filters
merge_request: 61230
author:
type: fixed
......@@ -866,5 +866,36 @@ RSpec.describe MergeRequestsFinder do
end
end
end
describe '#count_by_state' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:labels) { create_list(:label, 2, project: project) }
let_it_be(:merge_requests) { create_list(:merge_request, 4, :unique_branches, author: user, target_project: project, source_project: project, labels: labels) }
before do
project.add_developer(user)
end
context 'when filtering by multiple labels' do
it 'returns the correnct counts' do
counts = described_class.new(user, { label_name: labels.map(&:name) }).count_by_state
expect(counts[:all]).to eq(merge_requests.size)
end
end
context 'when filtering by approved_by_usernames' do
before do
merge_requests.each { |mr| mr.approved_by_users << user }
end
it 'returns the correnct counts' do
counts = described_class.new(user, { approved_by_usernames: [user.username] }).count_by_state
expect(counts[:all]).to eq(merge_requests.size)
end
end
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