Commit defc74fe authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '327320-feature-flag-remove-cached_sidebar_open_epics_count' into 'master'

Remove cached_sidebar_open_epics_count feature flag [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!62940
parents 39a50a66 b763267d
---
name: cached_sidebar_open_epics_count
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58064
rollout_issue_url:
milestone: '13.11'
type: development
group: group::product planning
default_enabled: true
......@@ -385,32 +385,7 @@ To remove a child epic from a parent epic:
## Cached epic count
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/299540) in GitLab 13.11.
> - It's [deployed behind a feature flag](../../feature_flags.md), enabled by default.
> - It's enabled on GitLab.com.
> - It's recommended for production use.
> - For GitLab self-managed instances, GitLab administrators can opt to [disable it](#enable-or-disable-cached-epic-count).
WARNING:
This feature might not be available to you. Check the **version history** note above for details.
> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/issues/327320) in GitLab 14.0.
In a group, the sidebar displays the total count of open epics and this value is cached if higher
than 1000. The cached value is rounded to thousands (or millions) and updated every 24 hours.
### Enable or disable cached epic count **(PREMIUM SELF)**
Cached epic count in the left sidebar is under development but ready for production use. It is
deployed behind a feature flag that is **enabled by default**.
[GitLab administrators with access to the GitLab Rails console](../../../administration/feature_flags.md)
can disable it.
To disable it:
```ruby
Feature.disable(:cached_sidebar_open_epics_count)
```
To enable it:
```ruby
Feature.enable(:cached_sidebar_open_epics_count)
```
......@@ -4,21 +4,6 @@ module EE
module GroupsHelper
extend ::Gitlab::Utils::Override
def group_epics_count(state:)
EpicsFinder
.new(current_user, group_id: @group.id, state: state)
.execute(skip_visibility_check: true)
.count
end
def open_epics_count(group)
if ::Feature.enabled?(:cached_sidebar_open_epics_count, group, default_enabled: :yaml)
cached_issuables_count(group, type: :epics)
else
number_with_delimiter(group_epics_count(state: 'opened'))
end
end
override :issuables_count_service_class
def issuables_count_service_class(type)
return super unless type == :epics
......
- return unless group_sidebar_link?(:epics)
- epics_count = open_epics_count(group)
- epics_count = cached_issuables_count(group, type: :epics)
- epics_items = ['epics#show', 'epics#index', 'epic_boards#index', 'epic_boards#show', 'roadmap#show']
= nav_link(path: epics_items) do
......
......@@ -16,73 +16,31 @@ RSpec.describe GroupsHelper do
group.add_owner(owner)
end
describe '#group_epics_count' do
before do
stub_licensed_features(epics: true)
end
describe 'filtering by state' do
before do
create_list(:epic, 3, :opened, group: group)
create_list(:epic, 2, :closed, group: group)
end
it 'returns open epics count' do
expect(helper.group_epics_count(state: 'opened')).to eq(3)
end
it 'returns closed epics count' do
expect(helper.group_epics_count(state: 'closed')).to eq(2)
end
end
it 'counts also epics from subgroups not visible to user' do
parent_group = create(:group, :public)
subgroup = create(:group, :private, parent: parent_group)
create(:epic, :opened, group: parent_group)
create(:epic, :opened, group: subgroup)
helper.instance_variable_set(:@group, parent_group)
expect(Ability.allowed?(owner, :read_epic, parent_group)).to be_truthy
expect(Ability.allowed?(owner, :read_epic, subgroup)).to be_falsey
expect(helper.group_epics_count(state: 'opened')).to eq(2)
end
end
describe '#open_epics_count' do
let_it_be(:count_service) { ::Groups::EpicsCountService }
before do
allow(helper).to receive(:current_user) { current_user }
end
it 'returns count value from cache' do
allow_next_instance_of(count_service) do |service|
allow(service).to receive(:count).and_return(2500)
end
expect(helper.open_epics_count(group)).to eq('2.5k')
end
context 'when cached_sidebar_open_epics_count feature flag is disabled' do
before do
stub_feature_flags(cached_sidebar_open_epics_count: false)
end
it 'returns not cached epics count' do
allow(helper).to receive(:group_epics_count).and_return(2500)
expect(helper.open_epics_count(group)).to eq('2,500')
end
end
end
describe '#cached_issuables_count' do
context 'with epics type' do
let(:type) { :epics }
let(:count_service) { ::Groups::EpicsCountService }
it_behaves_like 'cached issuables count'
context 'with subgroup epics' do
before do
stub_licensed_features(epics: true)
allow(helper).to receive(:current_user) { owner }
allow(count_service).to receive(:new).and_call_original
end
it 'counts also epics from subgroups not visible to user' do
parent_group = create(:group, :public)
subgroup = create(:group, :private, parent: parent_group)
create(:epic, :opened, group: parent_group)
create(:epic, :opened, group: subgroup)
expect(Ability.allowed?(owner, :read_epic, parent_group)).to be_truthy
expect(Ability.allowed?(owner, :read_epic, subgroup)).to be_falsey
expect(helper.cached_issuables_count(parent_group, type: type)).to eq('2')
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