nostrdb

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

commit ae4ec323891057d54382a2dddc483f183b208e1b
parent a80b7c5d9ccf2540b07265ca36c2b810682ef1f6
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 *);