From 32ae15741c1d69eea8ebcf7525957af046e69c74 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Tue, 13 Jun 2023 10:12:14 +0200 Subject: [PATCH] refactor: read project ids in memory (#3965) --- .../features/playground/playground-service.ts | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/lib/features/playground/playground-service.ts b/src/lib/features/playground/playground-service.ts index 76ad00132a..376456c2d3 100644 --- a/src/lib/features/playground/playground-service.ts +++ b/src/lib/features/playground/playground-service.ts @@ -45,6 +45,13 @@ export class PlaygroundService { ), this.segmentService.getActive(), ]); + const featureProject: Record = features.reduce( + (obj, feature) => { + obj[feature.name] = feature.project; + return obj; + }, + {}, + ); const [head, ...rest] = features; if (!head) { @@ -68,37 +75,29 @@ export class PlaygroundService { ? new Date(context.currentTime) : undefined, }; - const output: PlaygroundFeatureSchema[] = await Promise.all( - client - .getFeatureToggleDefinitions() - .map(async (feature: FeatureInterface) => { - const strategyEvaluationResult: FeatureStrategiesEvaluationResult = - client.isEnabled(feature.name, clientContext); + const output: PlaygroundFeatureSchema[] = client + .getFeatureToggleDefinitions() + .map((feature: FeatureInterface) => { + const strategyEvaluationResult: FeatureStrategiesEvaluationResult = + client.isEnabled(feature.name, clientContext); - const isEnabled = - strategyEvaluationResult.result === true && - feature.enabled; + const isEnabled = + strategyEvaluationResult.result === true && + feature.enabled; - return { - isEnabled, - isEnabledInCurrentEnvironment: feature.enabled, - strategies: { - result: strategyEvaluationResult.result, - data: strategyEvaluationResult.strategies, - }, - projectId: - await this.featureToggleService.getProjectId( - feature.name, - ), - variant: client.getVariant( - feature.name, - clientContext, - ), - name: feature.name, - variants: variantsMap[feature.name] || [], - }; - }), - ); + return { + isEnabled, + isEnabledInCurrentEnvironment: feature.enabled, + strategies: { + result: strategyEvaluationResult.result, + data: strategyEvaluationResult.strategies, + }, + projectId: featureProject[feature.name], + variant: client.getVariant(feature.name, clientContext), + name: feature.name, + variants: variantsMap[feature.name] || [], + }; + }); return output; }