feed cache

This commit is contained in:
2023-02-01 13:22:11 +00:00
parent 1b4ac0d711
commit 48407d9198
17 changed files with 158 additions and 97 deletions

View File

@ -1,23 +1,35 @@
import Dexie, { Table } from "dexie";
import { TaggedRawEvent, u256 } from "Nostr";
import { MetadataCache } from "State/Users";
import { hexToBech32 } from "Util";
export const NAME = 'snortDB'
export const VERSION = 2
export const VERSION = 3
export interface SubCache {
id: string,
ids: u256[],
until?: number,
since?: number,
}
const STORES = {
users: '++pubkey, name, display_name, picture, nip05, npub'
users: '++pubkey, name, display_name, picture, nip05, npub',
events: '++id, pubkey, created_at',
feeds: '++id'
}
export class SnortDB extends Dexie {
users!: Table<MetadataCache>;
events!: Table<TaggedRawEvent>;
feeds!: Table<SubCache>;
constructor() {
super(NAME);
this.version(VERSION).stores(STORES).upgrade(tx => {
return tx.table("users").toCollection().modify(user => {
this.version(VERSION).stores(STORES).upgrade(async tx => {
await tx.table("users").toCollection().modify(user => {
user.npub = hexToBech32("npub", user.pubkey)
})
});
});
}
}