@launchdarkly/js-server-sdk-common
Advanced tools
Comparing version 1.1.1-beta.1 to 1.2.0
@@ -5,2 +5,15 @@ # Changelog | ||
## [1.2.0](https://github.com/launchdarkly/js-core/compare/js-server-sdk-common-v1.1.0...js-server-sdk-common-v1.2.0) (2023-08-21) | ||
### Features | ||
* Optimize segment lookup for large segments. ([#235](https://github.com/launchdarkly/js-core/issues/235)) ([ac575d0](https://github.com/launchdarkly/js-core/commit/ac575d011d64f1833fc4c61bbbb7e4542b42e568)) | ||
* Use callbacks for evaluation hotpath. ([#234](https://github.com/launchdarkly/js-core/issues/234)) ([27e5454](https://github.com/launchdarkly/js-core/commit/27e54543f70e554eb452616f44ed19fbd9086bd2)) | ||
### Bug Fixes | ||
* Correct double callback in persistent store wrapper. ([#240](https://github.com/launchdarkly/js-core/issues/240)) ([243729d](https://github.com/launchdarkly/js-core/commit/243729d258b81f71f88328fa0d406f3d5f3f1f80)) | ||
## [1.1.0](https://github.com/launchdarkly/js-core/compare/js-server-sdk-common-v1.0.8...js-server-sdk-common-v1.1.0) (2023-08-14) | ||
@@ -7,0 +20,0 @@ |
@@ -16,3 +16,5 @@ import { AttributeReference } from '@launchdarkly/js-sdk-common'; | ||
bucketByAttributeReference?: AttributeReference; | ||
generated_includedSet?: Set<string>; | ||
generated_excludedSet?: Set<string>; | ||
} | ||
//# sourceMappingURL=Segment.d.ts.map |
export interface SegmentTarget { | ||
contextKind: string; | ||
values: string[]; | ||
generated_valuesSet?: Set<string>; | ||
} | ||
//# sourceMappingURL=SegmentTarget.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function segmentSearch(context, contextTargets, userTargets) { | ||
function segmentSearch(context, contextTargets, userTargets, userTargetSet) { | ||
if (contextTargets) { | ||
@@ -8,3 +8,19 @@ for (let targetIndex = 0; targetIndex < contextTargets.length; targetIndex += 1) { | ||
const key = context.key(target.contextKind); | ||
if (key && target.values.includes(key)) { | ||
if (key) { | ||
if (target.generated_valuesSet) { | ||
// Only check generated_valuesSet if present. | ||
if (target.generated_valuesSet.has(key)) { | ||
return true; | ||
} | ||
} | ||
else if (target.values.includes(key)) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
if (userTargetSet) { | ||
const userKey = context.key('user'); | ||
if (userKey) { | ||
if (userTargetSet.has(userKey)) { | ||
return true; | ||
@@ -14,3 +30,3 @@ } | ||
} | ||
if (userTargets) { | ||
else if (userTargets) { | ||
const userKey = context.key('user'); | ||
@@ -26,7 +42,7 @@ if (userKey) { | ||
function matchSegmentTargets(segment, context) { | ||
const included = segmentSearch(context, segment.includedContexts, segment.included); | ||
const included = segmentSearch(context, segment.includedContexts, segment.included, segment.generated_includedSet); | ||
if (included) { | ||
return true; | ||
} | ||
const excluded = segmentSearch(context, segment.excludedContexts, segment.excluded); | ||
const excluded = segmentSearch(context, segment.excludedContexts, segment.excluded, segment.generated_excludedSet); | ||
if (excluded) { | ||
@@ -33,0 +49,0 @@ // The match was an exclusion, so it should be negated. |
@@ -203,5 +203,3 @@ "use strict"; | ||
else { | ||
this.featureStore.all(VersionedDataKinds_1.default.Features, (allFlags) => { | ||
doEval(true); | ||
}); | ||
doEval(true); | ||
} | ||
@@ -208,0 +206,0 @@ }); |
@@ -9,2 +9,4 @@ "use strict"; | ||
const VersionedDataKinds_1 = require("./VersionedDataKinds"); | ||
// The max size where we use an array instead of a set. | ||
const TARGET_LIST_ARRAY_CUTOFF = 100; | ||
/** | ||
@@ -41,2 +43,26 @@ * @internal | ||
} | ||
if (value.generated_includedSet) { | ||
value.included = [...value.generated_includedSet]; | ||
delete value.generated_includedSet; | ||
} | ||
if (value.generated_excludedSet) { | ||
value.excluded = [...value.generated_excludedSet]; | ||
delete value.generated_excludedSet; | ||
} | ||
if (value.includedContexts) { | ||
value.includedContexts.forEach((target) => { | ||
if (target.generated_valuesSet) { | ||
target.values = [...target.generated_valuesSet]; | ||
} | ||
delete target.generated_valuesSet; | ||
}); | ||
} | ||
if (value.excludedContexts) { | ||
value.excludedContexts.forEach((target) => { | ||
if (target.generated_valuesSet) { | ||
target.values = [...target.generated_valuesSet]; | ||
} | ||
delete target.generated_valuesSet; | ||
}); | ||
} | ||
return value; | ||
@@ -79,4 +105,32 @@ } | ||
function processSegment(segment) { | ||
var _a; | ||
(_a = segment === null || segment === void 0 ? void 0 : segment.rules) === null || _a === void 0 ? void 0 : _a.forEach((rule) => { | ||
var _a, _b, _c, _d, _e; | ||
if (((_a = segment === null || segment === void 0 ? void 0 : segment.included) === null || _a === void 0 ? void 0 : _a.length) && segment.included.length > TARGET_LIST_ARRAY_CUTOFF) { | ||
segment.generated_includedSet = new Set(segment.included); | ||
delete segment.included; | ||
} | ||
if (((_b = segment === null || segment === void 0 ? void 0 : segment.excluded) === null || _b === void 0 ? void 0 : _b.length) && segment.excluded.length > TARGET_LIST_ARRAY_CUTOFF) { | ||
segment.generated_excludedSet = new Set(segment.excluded); | ||
delete segment.excluded; | ||
} | ||
if ((_c = segment === null || segment === void 0 ? void 0 : segment.includedContexts) === null || _c === void 0 ? void 0 : _c.length) { | ||
segment.includedContexts.forEach((target) => { | ||
var _a; | ||
if (((_a = target === null || target === void 0 ? void 0 : target.values) === null || _a === void 0 ? void 0 : _a.length) && target.values.length > TARGET_LIST_ARRAY_CUTOFF) { | ||
target.generated_valuesSet = new Set(target.values); | ||
// Currently typing is non-optional, so we don't delete it. | ||
target.values = []; | ||
} | ||
}); | ||
} | ||
if ((_d = segment === null || segment === void 0 ? void 0 : segment.excludedContexts) === null || _d === void 0 ? void 0 : _d.length) { | ||
segment.excludedContexts.forEach((target) => { | ||
var _a; | ||
if (((_a = target === null || target === void 0 ? void 0 : target.values) === null || _a === void 0 ? void 0 : _a.length) && target.values.length > TARGET_LIST_ARRAY_CUTOFF) { | ||
target.generated_valuesSet = new Set(target.values); | ||
// Currently typing is non-optional, so we don't delete it. | ||
target.values = []; | ||
} | ||
}); | ||
} | ||
(_e = segment === null || segment === void 0 ? void 0 : segment.rules) === null || _e === void 0 ? void 0 : _e.forEach((rule) => { | ||
var _a; | ||
@@ -83,0 +137,0 @@ if (rule.bucketBy) { |
{ | ||
"name": "@launchdarkly/js-server-sdk-common", | ||
"version": "1.1.1-beta.1", | ||
"version": "1.2.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
501185
7081
0