mikedilger / gossip

Gossip is a nostr client
Other
693 stars 77 forks source link

LMDB rekey #441

Open mikedilger opened 1 year ago

mikedilger commented 1 year ago

Notes to myself to come back to

mikedilger commented 1 year ago

Here is what I wrote on nostr:

Ok I enumerated all the ways I search the data, organized them into groups of similar inputs, and came up with five indexes that I think not only cover every case but do so efficiently:

Never do I search events not knowing the event kinds I care about. So I can always put event kind first in an index.

I: EventKind + PublicKey(author) + ReverseCreatedAt -> Id [DUP KEYS]

This covers followed feed, half of inbox, half of person feed, replacing a replaceable (not parameterized) event, finding DMs and finding contact lists.

II: Id + Relationship -> Id [DUP KEYS]

This builds threads. Easily find all replies to an event. Also used to find reactions, zaps, and deletions.

III: ReverseCreatedAt -> Id [DUP KEYS]

This stores and retrieves only events that reference you. This has to be rebuilt if you change your key. Instant inbox, except is misses events that blindly refer to my events (with no p-tag). We can get those through I.

IV: EventKind + PublicKey(of-delegation-tag) + ReverseCreatedAt -> Id [DUP KEYS]

This stores all delegated events. It finishes the person feed (NIP-26 support). Should be small as few events are delegated.

V: EventKind + PublicKey(author) + D-tag -> Id [UNIQUE KEYS]

This is for finding/replacing parameterized replaceable events.