diff --git a/flagsmith-engine/features/models.ts b/flagsmith-engine/features/models.ts index 8c8b0d8..7fda867 100644 --- a/flagsmith-engine/features/models.ts +++ b/flagsmith-engine/features/models.ts @@ -96,18 +96,27 @@ export class FeatureStateModel { } return this.featureSegment.priority < other.featureSegment.priority; } - - getMultivariateValue(identityID: number | string) { - const percentageValue = getHashedPercentateForObjIds([ - this.djangoID || this.featurestateUUID, - identityID - ]); + getMultivariateValue(identityID: number | string) { + let percentageValue: number | undefined; let startPercentage = 0; - const sortedF = this.multivariateFeatureStateValues.sort((a, b) =>{ + const sortedF = this.multivariateFeatureStateValues.sort((a, b) => { return a.id - b.id; }); for (const myValue of sortedF) { + switch (myValue.percentageAllocation) { + case 0: + continue; + case 100: + return myValue.multivariateFeatureOption.value; + default: + if (percentageValue === undefined) { + percentageValue = getHashedPercentateForObjIds([ + this.djangoID || this.featurestateUUID, + identityID + ]); + } + } const limit = myValue.percentageAllocation + startPercentage; if (startPercentage <= percentageValue && percentageValue < limit) { return myValue.multivariateFeatureOption.value;