1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

refactor: read project ids in memory (#3965)

This commit is contained in:
Mateusz Kwasniewski 2023-06-13 10:12:14 +02:00 committed by GitHub
parent f8ca7c91df
commit 32ae15741c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,6 +45,13 @@ export class PlaygroundService {
),
this.segmentService.getActive(),
]);
const featureProject: Record<string, string> = 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;
}