mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-26 01:17:00 +02:00
feat: configurable playground limit (#4047)
This commit is contained in:
parent
7c5971a2b4
commit
ffed4e78b0
@ -48,6 +48,7 @@ export class PlaygroundService {
|
|||||||
projects: typeof ALL | string[],
|
projects: typeof ALL | string[],
|
||||||
environments: string[],
|
environments: string[],
|
||||||
context: SdkContextSchema,
|
context: SdkContextSchema,
|
||||||
|
limit: number,
|
||||||
): Promise<AdvancedPlaygroundFeatureSchema[]> {
|
): Promise<AdvancedPlaygroundFeatureSchema[]> {
|
||||||
const segments = await this.segmentService.getActive();
|
const segments = await this.segmentService.getActive();
|
||||||
const environmentFeatures = await Promise.all(
|
const environmentFeatures = await Promise.all(
|
||||||
@ -59,6 +60,7 @@ export class PlaygroundService {
|
|||||||
environments.length,
|
environments.length,
|
||||||
environmentFeatures[0]?.features.length ?? 0,
|
environmentFeatures[0]?.features.length ?? 0,
|
||||||
contexts.length,
|
contexts.length,
|
||||||
|
limit,
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
|
@ -106,12 +106,19 @@ export default class PlaygroundController extends Controller {
|
|||||||
res: Response<AdvancedPlaygroundResponseSchema>,
|
res: Response<AdvancedPlaygroundResponseSchema>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (this.flagResolver.isEnabled('advancedPlayground')) {
|
if (this.flagResolver.isEnabled('advancedPlayground')) {
|
||||||
|
const { payload } =
|
||||||
|
this.flagResolver.getVariant('advancedPlayground');
|
||||||
|
const limit =
|
||||||
|
payload?.value && Number.isInteger(parseInt(payload?.value))
|
||||||
|
? parseInt(payload?.value)
|
||||||
|
: 15000;
|
||||||
res.json({
|
res.json({
|
||||||
input: req.body,
|
input: req.body,
|
||||||
features: await this.playgroundService.evaluateAdvancedQuery(
|
features: await this.playgroundService.evaluateAdvancedQuery(
|
||||||
req.body.projects || '*',
|
req.body.projects || '*',
|
||||||
req.body.environments,
|
req.body.environments,
|
||||||
req.body.context,
|
req.body.context,
|
||||||
|
limit,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,6 +6,7 @@ export const validateQueryComplexity = (
|
|||||||
environmentsCount: number,
|
environmentsCount: number,
|
||||||
featuresCount: number,
|
featuresCount: number,
|
||||||
contextCombinationsCount: number,
|
contextCombinationsCount: number,
|
||||||
|
limit = MAX_COMPLEXITY,
|
||||||
): void => {
|
): void => {
|
||||||
const totalCount =
|
const totalCount =
|
||||||
environmentsCount * featuresCount * contextCombinationsCount;
|
environmentsCount * featuresCount * contextCombinationsCount;
|
||||||
@ -13,7 +14,7 @@ export const validateQueryComplexity = (
|
|||||||
const reason = `Rejecting evaluation as it would generate ${totalCount} combinations exceeding ${MAX_COMPLEXITY} limit. `;
|
const reason = `Rejecting evaluation as it would generate ${totalCount} combinations exceeding ${MAX_COMPLEXITY} limit. `;
|
||||||
const action = `Please reduce the number of selected environments (${environmentsCount}), features (${featuresCount}), context field combinations (${contextCombinationsCount}).`;
|
const action = `Please reduce the number of selected environments (${environmentsCount}), features (${featuresCount}), context field combinations (${contextCombinationsCount}).`;
|
||||||
|
|
||||||
if (totalCount > MAX_COMPLEXITY) {
|
if (totalCount > limit) {
|
||||||
throw new BadDataError(reason + action);
|
throw new BadDataError(reason + action);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user