nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 5201dc464424c15d7f40c13ed06ade245d741963
parent d842d7471ec2af518d2c1e8276bce704458a1b22
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  7 Sep 2023 10:47:24 -0700

optimized function just for fetching notekeys from indices

Diffstat:
Mnostrdb.c | 10++++++++++
Mnostrdb.h | 2++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/nostrdb.c b/nostrdb.c @@ -351,6 +351,16 @@ struct ndb_note *ndb_get_note_by_id(struct ndb_txn *txn, const unsigned char *id return ndb_lookup_tsid(txn, NDB_DB_NOTE_ID, NDB_DB_NOTE, id, len, key); } +uint64_t ndb_get_notekey_by_id(struct ndb_txn *txn, const unsigned char *id) +{ + MDB_val k; + + if (!ndb_get_tsid(txn->mdb_txn, &txn->ndb->lmdb, NDB_DB_NOTE_ID, id, &k)) + return 0; + + return *(uint64_t*)k.mv_data; +} + struct ndb_note *ndb_get_note_by_key(struct ndb_txn *txn, uint64_t key, size_t *len) { return ndb_lookup_by_key(txn, key, NDB_DB_NOTE, len); diff --git a/nostrdb.h b/nostrdb.h @@ -164,6 +164,8 @@ int ndb_process_events(struct ndb *, const char *ldjson, size_t len); int ndb_begin_query(struct ndb *, struct ndb_txn *); void ndb_end_query(struct ndb_txn *); void *ndb_get_profile_by_pubkey(struct ndb_txn *txn, const unsigned char *pubkey, size_t *len, uint64_t *primkey); +void *ndb_get_profile_by_key(struct ndb_txn *txn, uint64_t key, size_t *len); +uint64_t ndb_get_notekey_by_id(struct ndb_txn *txn, const unsigned char *id); struct ndb_note *ndb_get_note_by_id(struct ndb_txn *txn, const unsigned char *id, size_t *len, uint64_t *primkey); struct ndb_note *ndb_get_note_by_key(struct ndb_txn *txn, uint64_t key, size_t *len); void ndb_destroy(struct ndb *);