mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01: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[],
|
||||
environments: string[],
|
||||
context: SdkContextSchema,
|
||||
limit: number,
|
||||
): Promise<AdvancedPlaygroundFeatureSchema[]> {
|
||||
const segments = await this.segmentService.getActive();
|
||||
const environmentFeatures = await Promise.all(
|
||||
@ -59,6 +60,7 @@ export class PlaygroundService {
|
||||
environments.length,
|
||||
environmentFeatures[0]?.features.length ?? 0,
|
||||
contexts.length,
|
||||
limit,
|
||||
);
|
||||
|
||||
const results = await Promise.all(
|
||||
|
@ -106,12 +106,19 @@ export default class PlaygroundController extends Controller {
|
||||
res: Response<AdvancedPlaygroundResponseSchema>,
|
||||
): Promise<void> {
|
||||
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({
|
||||
input: req.body,
|
||||
features: await this.playgroundService.evaluateAdvancedQuery(
|
||||
req.body.projects || '*',
|
||||
req.body.environments,
|
||||
req.body.context,
|
||||
limit,
|
||||
),
|
||||
});
|
||||
} else {
|
||||
|
@ -6,6 +6,7 @@ export const validateQueryComplexity = (
|
||||
environmentsCount: number,
|
||||
featuresCount: number,
|
||||
contextCombinationsCount: number,
|
||||
limit = MAX_COMPLEXITY,
|
||||
): void => {
|
||||
const totalCount =
|
||||
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 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);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user