diff --git a/src/store/mod.rs b/src/store/mod.rs index edddf3a..6b2424b 100644 --- a/src/store/mod.rs +++ b/src/store/mod.rs @@ -17,6 +17,7 @@ pub struct Store { events: EventStore, env: Env, ids: Database, OwnedType>, + ci: Database, OwnedType>, akci: Database, OwnedType>, atci: Database, OwnedType>, ktci: Database, OwnedType>, @@ -57,6 +58,11 @@ impl Store { .types::, OwnedType>() .name("ids") .create(&mut txn)?; + let ci = env + .database_options() + .types::, OwnedType>() + .name("ci") + .create(&mut txn)?; let akci = env .database_options() .types::, OwnedType>() @@ -101,6 +107,7 @@ impl Store { events, env, ids, + ci, akci, atci, ktci, @@ -404,6 +411,10 @@ impl Store { // Index by id self.ids.put(txn, event.id().0.as_slice(), &offset)?; + // Index by created_at and id + self.ci + .put(txn, &Self::key_ci(event.created_at(), event.id()), &offset)?; + // Index by author and kind (with created_at and id) self.akci.put( txn, @@ -484,7 +495,9 @@ impl Store { } } - // Index by author and kind (with created_at and id) + self.ci + .delete(txn, &Self::key_ci(event.created_at(), event.id()))?; + self.akci.delete( txn, &Self::key_akci(event.pubkey(), event.kind(), event.created_at(), event.id()), @@ -585,6 +598,14 @@ impl Store { Ok(()) } + fn key_ci(created_at: Time, id: Id) -> Vec { + let mut key: Vec = + Vec::with_capacity(std::mem::size_of::