use @snort/system cache
This commit is contained in:
29
packages/system/src/cache/UserRelayCache.ts
vendored
Normal file
29
packages/system/src/cache/UserRelayCache.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
import { db, UsersRelays } from ".";
|
||||
import { FeedCache } from "@snort/shared";
|
||||
|
||||
export class UserRelaysCache extends FeedCache<UsersRelays> {
|
||||
constructor() {
|
||||
super("UserRelays", db.userRelays);
|
||||
}
|
||||
|
||||
key(of: UsersRelays): string {
|
||||
return of.pubkey;
|
||||
}
|
||||
|
||||
override async preload(follows?: Array<string>): Promise<void> {
|
||||
await super.preload();
|
||||
if (follows) {
|
||||
await this.buffer(follows);
|
||||
}
|
||||
}
|
||||
|
||||
newest(): number {
|
||||
let ret = 0;
|
||||
this.cache.forEach(v => (ret = v.created_at > ret ? v.created_at : ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
takeSnapshot(): Array<UsersRelays> {
|
||||
return [...this.cache.values()];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user