Skip to content

Commit 1fb838c

Browse files
authored
Fix hash lookup order (#499)
1 parent 421cce7 commit 1fb838c

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

src/StatsigStore.ts

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -838,16 +838,14 @@ export default class StatsigStore {
838838
gateName: string,
839839
ignoreOverrides = false,
840840
): StoreGateFetchResult {
841-
const gateNameHash = this.getHashedSpecName(gateName);
842841
let gateValue: APIFeatureGate = {
843842
name: gateName,
844843
value: false,
845844
rule_id: '',
846845
secondary_exposures: [],
847846
};
848847
let details: EvaluationDetails;
849-
const userGateOverride =
850-
this.overrides.gates[gateNameHash] ?? this.overrides.gates[gateName];
848+
const userGateOverride = this.overrides.gates[gateName];
851849
if (!ignoreOverrides && userGateOverride != null) {
852850
gateValue = {
853851
name: gateName,
@@ -861,8 +859,8 @@ export default class StatsigStore {
861859
);
862860
} else {
863861
const value =
864-
this.userValues?.feature_gates[gateNameHash] ??
865-
this.userValues?.feature_gates[gateName];
862+
this.userValues?.feature_gates[gateName] ??
863+
this.userValues?.feature_gates[this.getHashedSpecName(gateName)];
866864
if (value) {
867865
gateValue = value;
868866
}
@@ -873,15 +871,9 @@ export default class StatsigStore {
873871
}
874872

875873
public getConfig(configName: string, ignoreOverrides = false): DynamicConfig {
876-
const configNameHash = this.getHashedSpecName(configName);
877874
let configValue: DynamicConfig;
878875
let details: EvaluationDetails;
879-
const userConfigValue =
880-
this.userValues?.dynamic_configs[configNameHash] ??
881-
this.userValues?.dynamic_configs[configName];
882-
const userConfigOverride =
883-
this.overrides.configs[configNameHash] ??
884-
this.overrides.configs[configName];
876+
const userConfigOverride = this.overrides.configs[configName];
885877
if (!ignoreOverrides && userConfigOverride != null) {
886878
details = this.getEvaluationDetails(
887879
false,
@@ -898,16 +890,22 @@ export default class StatsigStore {
898890
this.sdkInternal.getCurrentUser(),
899891
),
900892
);
901-
} else if (userConfigValue != null) {
902-
details = this.getEvaluationDetails(true);
903-
configValue = this.createDynamicConfig(
904-
configName,
905-
userConfigValue,
906-
details,
907-
);
908893
} else {
909-
details = this.getEvaluationDetails(false);
910-
configValue = new DynamicConfig(configName, {}, '', details);
894+
const userConfigValue =
895+
this.userValues?.dynamic_configs[configName] ??
896+
this.userValues?.dynamic_configs[this.getHashedSpecName(configName)];
897+
898+
if (userConfigValue != null) {
899+
details = this.getEvaluationDetails(true);
900+
configValue = this.createDynamicConfig(
901+
configName,
902+
userConfigValue,
903+
details,
904+
);
905+
} else {
906+
details = this.getEvaluationDetails(false);
907+
configValue = new DynamicConfig(configName, {}, '', details);
908+
}
911909
}
912910

913911
return configValue;
@@ -920,9 +918,7 @@ export default class StatsigStore {
920918
): DynamicConfig {
921919
let exp: DynamicConfig;
922920
let details: EvaluationDetails;
923-
const expNameHash = this.getHashedSpecName(expName);
924-
const userExpOverride =
925-
this.overrides.configs[expNameHash] ?? this.overrides.configs[expName];
921+
const userExpOverride = this.overrides.configs[expName];
926922
if (!ignoreOverrides && userExpOverride != null) {
927923
details = this.getEvaluationDetails(
928924
false,
@@ -951,10 +947,7 @@ export default class StatsigStore {
951947
layerName: string,
952948
keepDeviceValue: boolean,
953949
): Layer {
954-
const layerHashedName = this.getHashedSpecName(layerName);
955-
const userLayerOverride =
956-
this.overrides.layers[layerHashedName] ??
957-
this.overrides.layers[layerName];
950+
const userLayerOverride = this.overrides.layers[layerName];
958951
if (userLayerOverride != null) {
959952
const details = this.getEvaluationDetails(
960953
false,
@@ -1077,10 +1070,9 @@ export default class StatsigStore {
10771070
name: string,
10781071
topLevelKey: 'layer_configs' | 'dynamic_configs',
10791072
): APIDynamicConfig | undefined {
1080-
const hash = this.getHashedSpecName(name);
10811073
return (
1082-
this.userValues?.[topLevelKey]?.[hash] ??
1083-
this.userValues?.[topLevelKey]?.[name]
1074+
this.userValues?.[topLevelKey]?.[name] ??
1075+
this.userValues?.[topLevelKey]?.[this.getHashedSpecName(name)]
10841076
);
10851077
}
10861078

0 commit comments

Comments
 (0)