Skip to content

Commit

Permalink
feat: frontend api clean up not needed columns (#6489)
Browse files Browse the repository at this point in the history
1. Clean up not used fields
2. Fix a bug where segment was not attached
  • Loading branch information
sjaanus committed Mar 11, 2024
1 parent 2997fae commit 0cf7b32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/lib/proxy/client-feature-toggle-read-model.ts
Expand Up @@ -36,7 +36,6 @@ export default class ClientFeatureToggleReadModel
'features.project as project',
'features.stale as stale',
'features.impression_data as impression_data',
'features.created_at as created_at',
'fe.variants as variants',
'fe.enabled as enabled',
'fe.environment as environment',
Expand Down Expand Up @@ -118,7 +117,6 @@ export default class ClientFeatureToggleReadModel
project: row.project,
stale: row.stale,
type: row.type,
dependencies: [],
};
}

Expand All @@ -142,6 +140,9 @@ export default class ClientFeatureToggleReadModel
feature.strategies = feature.strategies || [];
feature.strategies.push(this.rowToStrategy(row));
}
if (row.segment_id) {
this.addSegmentIdsToStrategy(feature, row);
}
});
Object.values(featureTogglesByEnv).forEach((envFeatures) => {
Object.values(envFeatures).forEach((feature) => {
Expand All @@ -158,6 +159,22 @@ export default class ClientFeatureToggleReadModel
return featureTogglesByEnv;
}

private addSegmentIdsToStrategy(
feature: PartialDeep<IFeatureToggleClient>,
row: Record<string, any>,
) {
const strategy = feature.strategies?.find(
(s) => s?.id === row.strategy_id,
);
if (!strategy) {
return;
}
if (!strategy.segments) {
strategy.segments = [];
}
strategy.segments.push(row.segment_id);
}

private rowToStrategy(row: Record<string, any>): IStrategyConfig {
const strategy: IStrategyConfig = {
id: row.strategy_id,
Expand Down
10 changes: 8 additions & 2 deletions src/lib/proxy/proxy-service.ts
Expand Up @@ -82,7 +82,10 @@ export class ProxyService {

return definitions
.filter((feature) =>
client.isEnabled(feature.name, { ...context, sessionId }),
client.isEnabled(feature.name, {
...context,
sessionId,
}),
)
.map((feature) => ({
name: feature.name,
Expand Down Expand Up @@ -155,7 +158,10 @@ export class ProxyService {
);

await this.services.clientMetricsServiceV2.registerClientMetrics(
{ ...metrics, environment },
{
...metrics,
environment,
},
ip,
);
}
Expand Down

0 comments on commit 0cf7b32

Please sign in to comment.