This commit is contained in:
2023-03-29 13:10:22 +01:00
parent 8c44d123bd
commit c731c65661
27 changed files with 384 additions and 239 deletions

View File

@ -0,0 +1,36 @@
import { RawEvent } from "@snort/nostr";
import { db } from "Db";
import { dedupe } from "Util";
import FeedCache from "./FeedCache";
class DMCache extends FeedCache<RawEvent> {
constructor() {
super("DMCache", db.dms);
}
key(of: RawEvent): string {
return of.id;
}
override async preload(): Promise<void> {
await super.preload();
// load all dms to memory
await this.buffer([...this.onTable]);
}
newest(): number {
let ret = 0;
this.cache.forEach(v => (ret = v.created_at > ret ? v.created_at : ret));
return ret;
}
allDms(): Array<RawEvent> {
return [...this.cache.values()];
}
takeSnapshot(): Array<RawEvent> {
return this.allDms();
}
}
export const DmCache = new DMCache();