Commit 7a7e39e7 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'confidential-epics-usage' into 'master'

Add confidential epics count to usage data

See merge request gitlab-org/gitlab!32443
parents 317cc11c 9e44c75c
# frozen_string_literal: true
class AddEpicsConfidentialIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :epics, :confidential
end
def down
remove_concurrent_index :epics, :confidential
end
end
...@@ -9582,6 +9582,8 @@ CREATE INDEX index_epics_on_author_id ON public.epics USING btree (author_id); ...@@ -9582,6 +9582,8 @@ CREATE INDEX index_epics_on_author_id ON public.epics USING btree (author_id);
CREATE INDEX index_epics_on_closed_by_id ON public.epics USING btree (closed_by_id); CREATE INDEX index_epics_on_closed_by_id ON public.epics USING btree (closed_by_id);
CREATE INDEX index_epics_on_confidential ON public.epics USING btree (confidential);
CREATE INDEX index_epics_on_due_date_sourcing_epic_id ON public.epics USING btree (due_date_sourcing_epic_id) WHERE (due_date_sourcing_epic_id IS NOT NULL); CREATE INDEX index_epics_on_due_date_sourcing_epic_id ON public.epics USING btree (due_date_sourcing_epic_id) WHERE (due_date_sourcing_epic_id IS NOT NULL);
CREATE INDEX index_epics_on_due_date_sourcing_milestone_id ON public.epics USING btree (due_date_sourcing_milestone_id); CREATE INDEX index_epics_on_due_date_sourcing_milestone_id ON public.epics USING btree (due_date_sourcing_milestone_id);
...@@ -13867,5 +13869,6 @@ COPY "schema_migrations" (version) FROM STDIN; ...@@ -13867,5 +13869,6 @@ COPY "schema_migrations" (version) FROM STDIN;
20200514000132 20200514000132
20200514000340 20200514000340
20200515155620 20200515155620
20200519115908
\. \.
...@@ -69,7 +69,6 @@ module EE ...@@ -69,7 +69,6 @@ module EE
scope :in_issues, -> (issues) { joins(:epic_issues).where(epic_issues: { issue_id: issues }).distinct } scope :in_issues, -> (issues) { joins(:epic_issues).where(epic_issues: { issue_id: issues }).distinct }
scope :has_parent, -> { where.not(parent_id: nil) } scope :has_parent, -> { where.not(parent_id: nil) }
scope :iid_starts_with, -> (query) { where("CAST(iid AS VARCHAR) LIKE ?", "#{sanitize_sql_like(query)}%") } scope :iid_starts_with, -> (query) { where("CAST(iid AS VARCHAR) LIKE ?", "#{sanitize_sql_like(query)}%") }
scope :public_only, -> { where(confidential: false) }
scope :within_timeframe, -> (start_date, end_date) do scope :within_timeframe, -> (start_date, end_date) do
where('start_date is not NULL or end_date is not NULL') where('start_date is not NULL or end_date is not NULL')
...@@ -107,8 +106,10 @@ module EE ...@@ -107,8 +106,10 @@ module EE
scope :counts_by_state, -> { group(:state_id).count } scope :counts_by_state, -> { group(:state_id).count }
scope :public_only, -> { where(confidential: false) }
scope :confidential, -> { where(confidential: true) }
scope :not_confidential_or_in_groups, -> (groups) do scope :not_confidential_or_in_groups, -> (groups) do
where.not(confidential: true).or(where(confidential: true, group_id: groups)) public_only.or(where(confidential: true, group_id: groups))
end end
MAX_HIERARCHY_DEPTH = 5 MAX_HIERARCHY_DEPTH = 5
......
---
title: Added DB index on confidential epics column.
merge_request: 32443
author:
type: other
...@@ -156,6 +156,7 @@ module EE ...@@ -156,6 +156,7 @@ module EE
super.tap do |usage_data| super.tap do |usage_data|
usage_data[:counts].merge!( usage_data[:counts].merge!(
{ {
confidential_epics: count(::Epic.confidential),
dependency_list_usages_total: redis_usage_data { ::Gitlab::UsageCounters::DependencyList.usage_totals[:total] }, dependency_list_usages_total: redis_usage_data { ::Gitlab::UsageCounters::DependencyList.usage_totals[:total] },
epics: count(::Epic), epics: count(::Epic),
feature_flags: count(Operations::FeatureFlag), feature_flags: count(Operations::FeatureFlag),
......
...@@ -79,6 +79,7 @@ describe Gitlab::UsageData do ...@@ -79,6 +79,7 @@ describe Gitlab::UsageData do
expect(count_data[:projects]).to eq(3) expect(count_data[:projects]).to eq(3)
expect(count_data.keys).to include(*%i( expect(count_data.keys).to include(*%i(
confidential_epics
container_scanning_jobs container_scanning_jobs
dast_jobs dast_jobs
dependency_list_usages_total dependency_list_usages_total
......
...@@ -20,22 +20,26 @@ describe Epic do ...@@ -20,22 +20,26 @@ describe Epic do
end end
describe 'scopes' do describe 'scopes' do
let_it_be(:confidential_epic) { create(:epic, confidential: true, group: group) }
let_it_be(:public_epic) { create(:epic, group: group) }
describe '.public_only' do describe '.public_only' do
it 'only returns public epics' do it 'only returns public epics' do
public_epic = create(:epic)
create(:epic, confidential: true)
expect(described_class.public_only).to eq([public_epic]) expect(described_class.public_only).to eq([public_epic])
end end
end end
describe '.confidential' do
it 'only returns confidential epics' do
expect(described_class.confidential).to eq([confidential_epic])
end
end
describe '.not_confidential_or_in_groups' do describe '.not_confidential_or_in_groups' do
it 'returns only epics which are either not confidential or in the group' do it 'returns only epics which are either not confidential or in the group' do
confidential_epic = create(:epic, confidential: true, group: group)
group_epic = create(:epic, group: group)
create(:epic, confidential: true) create(:epic, confidential: true)
expect(described_class.not_confidential_or_in_groups(group)).to match_array([confidential_epic, group_epic]) expect(described_class.not_confidential_or_in_groups(group)).to match_array([confidential_epic, public_epic])
end 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