Skip to content

Commit

Permalink
Merge pull request #381 from splitio/consumer_mode_polishing
Browse files Browse the repository at this point in the history
Bugfix: handle rejected promises when using segment matchers
  • Loading branch information
EmilianoSanchez authored Dec 26, 2024
2 parents eafea0f + 4ebcff9 commit 1b9874e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.0.3 (December 29, 2024)
- Bugfixing - Properly handle rejected promises when using targeting rules with segment matchers in consumer modes (e.g., Redis and Pluggable storages).

2.0.2 (December 3, 2024)
- Updated the factory `init` and `destroy` methods to support re-initialization after destruction. This update ensures compatibility of the React SDK with React Strict Mode, where the factory's `init` and `destroy` effects are executed an extra time to validate proper resource cleanup.
- Bugfixing - Sanitize the `SplitSDKMachineName` header value to avoid exceptions on HTTP/S requests when it contains non ISO-8859-1 characters (Related to issue https://github.com/splitio/javascript-client/issues/847).
Expand Down
7 changes: 0 additions & 7 deletions src/evaluator/matchers/large_segment.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { MaybeThenable } from '../../dtos/types';
import { ISegmentsCacheBase } from '../../storages/types';
import { thenable } from '../../utils/promise/thenable';

export function largeSegmentMatcherContext(largeSegmentName: string, storage: { largeSegments?: ISegmentsCacheBase }) {

return function largeSegmentMatcher(key: string): MaybeThenable<boolean> {
const isInLargeSegment = storage.largeSegments ? storage.largeSegments.isInSegment(largeSegmentName, key) : false;

if (thenable(isInLargeSegment)) {
isInLargeSegment.then(result => {
return result;
});
}

return isInLargeSegment;
};
}
7 changes: 0 additions & 7 deletions src/evaluator/matchers/segment.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { MaybeThenable } from '../../dtos/types';
import { ISegmentsCacheBase } from '../../storages/types';
import { thenable } from '../../utils/promise/thenable';

export function segmentMatcherContext(segmentName: string, storage: { segments: ISegmentsCacheBase }) {

return function segmentMatcher(key: string): MaybeThenable<boolean> {
const isInSegment = storage.segments.isInSegment(segmentName, key);

if (thenable(isInSegment)) {
isInSegment.then(result => {
return result;
});
}

return isInSegment;
};
}
2 changes: 1 addition & 1 deletion src/storages/inRedis/SplitsCacheInRedis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
return Promise.reject(this.redisError);
}

const splits: Record<string, ISplit | null> = {};
const keys = names.map(name => this.keys.buildSplitKey(name));
return this.redis.mget(...keys)
.then(splitDefinitions => {
const splits: Record<string, ISplit | null> = {};
names.forEach((name, idx) => {
const split = splitDefinitions[idx];
splits[name] = split && JSON.parse(split);
Expand Down

0 comments on commit 1b9874e

Please sign in to comment.