mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: exclude archived features in segments count (#7886)
This commit is contained in:
parent
64a9caab30
commit
a89f05181d
@ -602,16 +602,32 @@ test('Should show usage in features and projects', async () => {
|
|||||||
);
|
);
|
||||||
const [feature] = await fetchFeatures();
|
const [feature] = await fetchFeatures();
|
||||||
const [strategy] = await fetchFeatureStrategies(feature.name);
|
const [strategy] = await fetchFeatureStrategies(feature.name);
|
||||||
//@ts-ignore
|
|
||||||
await addSegmentsToStrategy([segment.id], strategy.id);
|
|
||||||
|
|
||||||
const segments = await fetchSegments();
|
const unusedSegments = await fetchSegments();
|
||||||
expect(segments).toMatchObject([
|
expect(unusedSegments).toMatchObject([
|
||||||
|
{
|
||||||
|
usedInFeatures: 0,
|
||||||
|
usedInProjects: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await addSegmentsToStrategy([segment.id], strategy.id);
|
||||||
|
const usedSegments = await fetchSegments();
|
||||||
|
expect(usedSegments).toMatchObject([
|
||||||
{
|
{
|
||||||
usedInFeatures: 1,
|
usedInFeatures: 1,
|
||||||
usedInProjects: 1,
|
usedInProjects: 1,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
await app.archiveFeature(feature.name, feature.project);
|
||||||
|
const segmentsWithArchivedFeatures = await fetchSegments();
|
||||||
|
expect(segmentsWithArchivedFeatures).toMatchObject([
|
||||||
|
{
|
||||||
|
usedInFeatures: 0,
|
||||||
|
usedInProjects: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('detect strategy usage in change requests', () => {
|
describe('detect strategy usage in change requests', () => {
|
||||||
|
@ -16,6 +16,7 @@ import { isDefined } from '../../util';
|
|||||||
const T = {
|
const T = {
|
||||||
segments: 'segments',
|
segments: 'segments',
|
||||||
featureStrategies: 'feature_strategies',
|
featureStrategies: 'feature_strategies',
|
||||||
|
features: 'features',
|
||||||
featureStrategySegment: 'feature_strategy_segment',
|
featureStrategySegment: 'feature_strategy_segment',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -123,17 +124,15 @@ export default class SegmentStore implements ISegmentStore {
|
|||||||
|
|
||||||
private async getAllWithoutChangeRequestUsageData(): Promise<ISegment[]> {
|
private async getAllWithoutChangeRequestUsageData(): Promise<ISegment[]> {
|
||||||
const rows: ISegmentRow[] = await this.db
|
const rows: ISegmentRow[] = await this.db
|
||||||
.select(
|
.select([
|
||||||
this.prefixColumns(),
|
...this.prefixColumns(),
|
||||||
'used_in_projects',
|
this.db.raw(
|
||||||
'used_in_features',
|
`count(distinct case when ${T.features}.archived_at is null then ${T.featureStrategies}.project_name end) as used_in_projects`,
|
||||||
)
|
),
|
||||||
.countDistinct(
|
this.db.raw(
|
||||||
`${T.featureStrategies}.project_name AS used_in_projects`,
|
`count(distinct case when ${T.features}.archived_at is null then ${T.featureStrategies}.feature_name end) as used_in_features`,
|
||||||
)
|
),
|
||||||
.countDistinct(
|
])
|
||||||
`${T.featureStrategies}.feature_name AS used_in_features`,
|
|
||||||
)
|
|
||||||
.from(T.segments)
|
.from(T.segments)
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
T.featureStrategySegment,
|
T.featureStrategySegment,
|
||||||
@ -145,6 +144,11 @@ export default class SegmentStore implements ISegmentStore {
|
|||||||
`${T.featureStrategies}.id`,
|
`${T.featureStrategies}.id`,
|
||||||
`${T.featureStrategySegment}.feature_strategy_id`,
|
`${T.featureStrategySegment}.feature_strategy_id`,
|
||||||
)
|
)
|
||||||
|
.leftJoin(
|
||||||
|
T.features,
|
||||||
|
`${T.featureStrategies}.feature_name`,
|
||||||
|
`${T.features}.name`,
|
||||||
|
)
|
||||||
.groupBy(this.prefixColumns())
|
.groupBy(this.prefixColumns())
|
||||||
.orderBy('name', 'asc');
|
.orderBy('name', 'asc');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user