Skip to content

Commit

Permalink
exclude tags for other features (#3007)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Jan 27, 2023
1 parent d821b1e commit f8473a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/lib/db/feature-strategy-store.ts
Expand Up @@ -208,9 +208,9 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
const query = this.db
.select(COLUMNS)
.from<IFeatureStrategiesTable>(T.featureStrategies)
.where('environment', environment);
if (features) {
query.whereIn('feature_name', features);
.whereIn('feature_name', features);
if (environment) {
query.where('environment', environment);
}
const rows = await query;
return rows.map(mapRow);
Expand Down
13 changes: 13 additions & 0 deletions src/lib/db/feature-tag-store.ts
Expand Up @@ -105,6 +105,19 @@ class FeatureTagStore implements IFeatureTagStore {
return rows.map(this.featureTagRowToTag);
}

async getAllByFeatures(features: string[]): Promise<IFeatureTag[]> {
const query = this.db
.select(COLUMNS)
.from<FeatureTagTable>(TABLE)
.whereIn('feature_name', features);
const rows = await query;
return rows.map((row) => ({
featureName: row.feature_name,
tagType: row.tag_type,
tagValue: row.tag_value,
}));
}

async tagFeature(featureName: string, tag: ITag): Promise<ITag> {
const stopTimer = this.timer('tagFeature');
await this.db<FeatureTagTable>(TABLE)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/export-import-service.ts
Expand Up @@ -100,7 +100,7 @@ export default class ExportImportService {
),
this.segmentStore.getAllFeatureStrategySegments(),
this.contextFieldStore.getAll(),
this.featureTagStore.getAll(),
this.featureTagStore.getAllByFeatures(query.features),
this.segmentStore.getAll(),
]);
this.addSegmentsToStrategies(featureStrategies, strategySegments);
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/stores/feature-tag-store.ts
Expand Up @@ -13,6 +13,7 @@ export interface IFeatureAndTag {
}
export interface IFeatureTagStore extends Store<IFeatureTag, IFeatureTag> {
getAllTagsForFeature(featureName: string): Promise<ITag[]>;
getAllByFeatures(features: string[]): Promise<IFeatureTag[]>;
tagFeature(featureName: string, tag: ITag): Promise<ITag>;
importFeatureTags(featureTags: IFeatureTag[]): Promise<IFeatureAndTag[]>;
untagFeature(featureName: string, tag: ITag): Promise<void>;
Expand Down
8 changes: 8 additions & 0 deletions src/test/fixtures/fake-feature-tag-store.ts
Expand Up @@ -83,6 +83,14 @@ export default class FakeFeatureTagStore implements IFeatureTagStore {
});
return Promise.resolve();
}

getAllByFeatures(features: string[]): Promise<IFeatureTag[]> {
return Promise.resolve(
this.featureTags.filter((tag) =>
features.includes(tag.featureName),
),
);
}
}

module.exports = FakeFeatureTagStore;

0 comments on commit f8473a2

Please sign in to comment.