-
Notifications
You must be signed in to change notification settings - Fork 17
/
event-persister.ts
41 lines (39 loc) · 1.23 KB
/
event-persister.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// import {Event} from "./event";
// import {EventCache} from "./event-cache";
// export function persistCache(
// cache: EventCache,
// pubkey: string,
// follows: string[],
// capacity: number = 4000000
// ) {
// let events: Event[] = [];
// let kindsEvents = cache.authorsKindsByPubKey.get(pubkey);
// if (kindsEvents) {
// let mycapacity = capacity * 0.4;
// let sizes: [number, number][] = Array.from(kindsEvents).map((e, i) => [
// i,
// JSON.stringify(e).length,
// ]);
// sizes.sort((a, b) => b[1] - a[1]);
// let s = sizes.length;
// for (const [i, l] of sizes) {
// let allowedCapacity = mycapacity / s;
// let kindEvents: Event = kindsEvents.get(i);
// if (kindEvents) {
// let ke: Event[] = kindEvents;
// if (l < allowedCapacity) {
// events = events.concat(kindEvents);
// mycapacity -= l;
// } else {
// let partialEvents = kindEvents.slice(
// 0,
// kindEvents.length * Math.floor(allowedCapacity / l)
// );
// events = events.concat(partialEvents);
// }
// }
// }
// }
// }
// Needed for isolatedModules to not complain
export const __unused = true;