Skip to content

Commit 8377736

Browse files
Polishing in splits cache
1 parent be49475 commit 8377736

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

src/storages/inLocalStorage/SplitsCacheInLocal.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
121121
removeSplit(name: string): boolean {
122122
try {
123123
const split = this.getSplit(name);
124+
if (!split) return false;
125+
124126
localStorage.removeItem(this.keys.buildSplitKey(name));
125127

126128
this._decrementCounts(split);
@@ -133,7 +135,7 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
133135
}
134136
}
135137

136-
getSplit(name: string) {
138+
getSplit(name: string): ISplit | null {
137139
const item = localStorage.getItem(this.keys.buildSplitKey(name));
138140
return item && JSON.parse(item);
139141
}

src/storages/inMemory/SplitsCacheInMemory.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,35 @@ export class SplitsCacheInMemory extends AbstractSplitsCacheSync {
4141
if (usesSegments(previousSplit)) this.segmentsCount--;
4242
}
4343

44-
if (split) {
45-
// Store the Split.
46-
this.splitsCache[name] = split;
47-
// Update TT cache
48-
const ttName = split.trafficTypeName;
49-
this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
50-
this.addToFlagSets(split);
51-
52-
// Add to segments count for the new version of the Split
53-
if (usesSegments(split)) this.segmentsCount++;
54-
55-
return true;
56-
} else {
57-
return false;
58-
}
44+
// Store the Split.
45+
this.splitsCache[name] = split;
46+
// Update TT cache
47+
const ttName = split.trafficTypeName;
48+
this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
49+
this.addToFlagSets(split);
50+
51+
// Add to segments count for the new version of the Split
52+
if (usesSegments(split)) this.segmentsCount++;
53+
54+
return true;
5955
}
6056

6157
removeSplit(name: string): boolean {
6258
const split = this.getSplit(name);
63-
if (split) {
64-
// Delete the Split
65-
delete this.splitsCache[name];
59+
if (!split) return false;
6660

67-
const ttName = split.trafficTypeName;
68-
this.ttCache[ttName]--; // Update tt cache
69-
if (!this.ttCache[ttName]) delete this.ttCache[ttName];
70-
this.removeFromFlagSets(split.name, split.sets);
61+
// Delete the Split
62+
delete this.splitsCache[name];
7163

72-
// Update the segments count.
73-
if (usesSegments(split)) this.segmentsCount--;
64+
const ttName = split.trafficTypeName;
65+
this.ttCache[ttName]--; // Update tt cache
66+
if (!this.ttCache[ttName]) delete this.ttCache[ttName];
67+
this.removeFromFlagSets(split.name, split.sets);
7468

75-
return true;
76-
} else {
77-
return false;
78-
}
69+
// Update the segments count.
70+
if (usesSegments(split)) this.segmentsCount--;
71+
72+
return true;
7973
}
8074

8175
getSplit(name: string): ISplit | null {

0 commit comments

Comments
 (0)