Skip to content

Commit 8ca3490

Browse files
Refactor largeSegmentMatcher and segmentMatcher to remove unnecessary promise handling
1 parent 55f289d commit 8ca3490

File tree

3 files changed

+1
-15
lines changed

3 files changed

+1
-15
lines changed
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { MaybeThenable } from '../../dtos/types';
22
import { ISegmentsCacheBase } from '../../storages/types';
3-
import { thenable } from '../../utils/promise/thenable';
43

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

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

10-
if (thenable(isInLargeSegment)) {
11-
isInLargeSegment.then(result => {
12-
return result;
13-
});
14-
}
15-
169
return isInLargeSegment;
1710
};
1811
}

src/evaluator/matchers/segment.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { MaybeThenable } from '../../dtos/types';
22
import { ISegmentsCacheBase } from '../../storages/types';
3-
import { thenable } from '../../utils/promise/thenable';
43

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

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

10-
if (thenable(isInSegment)) {
11-
isInSegment.then(result => {
12-
return result;
13-
});
14-
}
15-
169
return isInSegment;
1710
};
1811
}

src/storages/inRedis/SplitsCacheInRedis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
266266
return Promise.reject(this.redisError);
267267
}
268268

269-
const splits: Record<string, ISplit | null> = {};
270269
const keys = names.map(name => this.keys.buildSplitKey(name));
271270
return this.redis.mget(...keys)
272271
.then(splitDefinitions => {
272+
const splits: Record<string, ISplit | null> = {};
273273
names.forEach((name, idx) => {
274274
const split = splitDefinitions[idx];
275275
splits[name] = split && JSON.parse(split);

0 commit comments

Comments
 (0)