From 0cf7b324a5664c7967c60f8ec9d168cd020e8c94 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Mon, 11 Mar 2024 13:41:41 +0200 Subject: [PATCH] feat: frontend api clean up not needed columns (#6489) 1. Clean up not used fields 2. Fix a bug where segment was not attached --- .../proxy/client-feature-toggle-read-model.ts | 21 +++++++++++++++++-- src/lib/proxy/proxy-service.ts | 10 +++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/lib/proxy/client-feature-toggle-read-model.ts b/src/lib/proxy/client-feature-toggle-read-model.ts index eb1bc364ef..ee91b1b9e4 100644 --- a/src/lib/proxy/client-feature-toggle-read-model.ts +++ b/src/lib/proxy/client-feature-toggle-read-model.ts @@ -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', @@ -118,7 +117,6 @@ export default class ClientFeatureToggleReadModel project: row.project, stale: row.stale, type: row.type, - dependencies: [], }; } @@ -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) => { @@ -158,6 +159,22 @@ export default class ClientFeatureToggleReadModel return featureTogglesByEnv; } + private addSegmentIdsToStrategy( + feature: PartialDeep, + row: Record, + ) { + 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): IStrategyConfig { const strategy: IStrategyConfig = { id: row.strategy_id, diff --git a/src/lib/proxy/proxy-service.ts b/src/lib/proxy/proxy-service.ts index 9a88df2a7c..7cfe814c62 100644 --- a/src/lib/proxy/proxy-service.ts +++ b/src/lib/proxy/proxy-service.ts @@ -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, @@ -155,7 +158,10 @@ export class ProxyService { ); await this.services.clientMetricsServiceV2.registerClientMetrics( - { ...metrics, environment }, + { + ...metrics, + environment, + }, ip, ); }