-
-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: exclude archived features in segments count #7886
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { isDefined } from '../../util'; | |
const T = { | ||
segments: 'segments', | ||
featureStrategies: 'feature_strategies', | ||
features: 'features', | ||
featureStrategySegment: 'feature_strategy_segment', | ||
}; | ||
|
||
|
@@ -123,17 +124,15 @@ export default class SegmentStore implements ISegmentStore { | |
|
||
private async getAllWithoutChangeRequestUsageData(): Promise<ISegment[]> { | ||
const rows: ISegmentRow[] = await this.db | ||
.select( | ||
this.prefixColumns(), | ||
'used_in_projects', | ||
'used_in_features', | ||
) | ||
.countDistinct( | ||
`${T.featureStrategies}.project_name AS used_in_projects`, | ||
) | ||
.countDistinct( | ||
`${T.featureStrategies}.feature_name AS used_in_features`, | ||
) | ||
.select([ | ||
...this.prefixColumns(), | ||
this.db.raw( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The COUNT functions are now wrapped with CASE statements. These CASE statements ensure that only non-archived features (where features.archived_at is NULL) are counted. If a feature is archived, the CASE returns NULL, which does not affect the count, effectively making it 0 |
||
`count(distinct case when ${T.features}.archived_at is null then ${T.featureStrategies}.project_name end) as used_in_projects`, | ||
), | ||
this.db.raw( | ||
`count(distinct case when ${T.features}.archived_at is null then ${T.featureStrategies}.feature_name end) as used_in_features`, | ||
), | ||
]) | ||
.from(T.segments) | ||
.leftJoin( | ||
T.featureStrategySegment, | ||
|
@@ -145,6 +144,11 @@ export default class SegmentStore implements ISegmentStore { | |
`${T.featureStrategies}.id`, | ||
`${T.featureStrategySegment}.feature_strategy_id`, | ||
) | ||
.leftJoin( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a new join to get feature archived info There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also tried the where clause just before groupBy instead of rewriting counts but it didn't work. |
||
T.features, | ||
`${T.featureStrategies}.feature_name`, | ||
`${T.features}.name`, | ||
) | ||
.groupBy(this.prefixColumns()) | ||
.orderBy('name', 'asc'); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't actually a typo, but shorthand for "if and only if", but maybe I should've written it out? 😅