Skip to content

Commit 8306cf6

Browse files
committed
chore: adapt fake store to new logic
1 parent 4fb225b commit 8306cf6

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
import type { IUnknownFlagsStore, UnknownFlag } from './unknown-flags-store';
22

33
export class FakeUnknownFlagsStore implements IUnknownFlagsStore {
4-
private unknownFlagRecord: Record<string, UnknownFlag> = {};
4+
private unknownFlagMap = new Map<string, UnknownFlag>();
5+
6+
private getKey(flag: UnknownFlag): string {
7+
return `${flag.name}:${flag.appName}`;
8+
}
59

610
async replaceAll(flags: UnknownFlag[]): Promise<void> {
7-
this.unknownFlagRecord = {};
11+
this.unknownFlagMap.clear();
812
for (const flag of flags) {
9-
this.unknownFlagRecord[flag.name] = flag;
13+
this.unknownFlagMap.set(this.getKey(flag), flag);
1014
}
1115
}
1216

1317
async getAll(): Promise<UnknownFlag[]> {
14-
return Object.values(this.unknownFlagRecord);
18+
return Array.from(this.unknownFlagMap.values());
1519
}
1620

1721
async clear(hoursAgo: number): Promise<void> {
18-
const now = new Date();
19-
for (const flag of Object.values(this.unknownFlagRecord)) {
20-
if (
21-
flag.seenAt.getTime() <
22-
now.getTime() - hoursAgo * 60 * 60 * 1000
23-
) {
24-
delete this.unknownFlagRecord[flag.name];
22+
const cutoff = Date.now() - hoursAgo * 60 * 60 * 1000;
23+
for (const [key, flag] of this.unknownFlagMap.entries()) {
24+
if (flag.seenAt.getTime() < cutoff) {
25+
this.unknownFlagMap.delete(key);
2526
}
2627
}
2728
}
2829

2930
async deleteAll(): Promise<void> {
30-
this.unknownFlagRecord = {};
31+
this.unknownFlagMap.clear();
3132
}
3233
}

0 commit comments

Comments
 (0)