nostrdb

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

commit f73c9a3a4f26d01b20185c709f915450b36ef01f
parent 5201dc464424c15d7f40c13ed06ade245d741963
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  7 Sep 2023 13:21:40 -0700

query: fix invalid type signature

Diffstat:
Mnostrdb.c | 22++++++++++++++++++----
Mnostrdb.h | 1+
2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/nostrdb.c b/nostrdb.c @@ -264,7 +264,9 @@ int ndb_get_tsid(MDB_txn *txn, struct ndb_lmdb *lmdb, enum ndb_dbs db, int success = 0; struct ndb_tsid tsid; + // position at the most recent ndb_tsid_high(&tsid, id); + k.mv_data = &tsid; k.mv_size = sizeof(tsid); @@ -351,14 +353,26 @@ 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) +static inline uint64_t ndb_get_indexkey_by_id(struct ndb_txn *txn, + enum ndb_dbs db, + const unsigned char *id) { MDB_val k; - if (!ndb_get_tsid(txn->mdb_txn, &txn->ndb->lmdb, NDB_DB_NOTE_ID, id, &k)) + if (!ndb_get_tsid(txn->mdb_txn, &txn->ndb->lmdb, db, id, &k)) return 0; - return *(uint64_t*)k.mv_data; + return *(uint32_t*)k.mv_data; +} + +uint64_t ndb_get_notekey_by_id(struct ndb_txn *txn, const unsigned char *id) +{ + return ndb_get_indexkey_by_id(txn, NDB_DB_NOTE_ID, id); +} + +uint64_t ndb_get_profilekey_by_pubkey(struct ndb_txn *txn, const unsigned char *id) +{ + return ndb_get_indexkey_by_id(txn, NDB_DB_PROFILE_PK, id); } struct ndb_note *ndb_get_note_by_key(struct ndb_txn *txn, uint64_t key, size_t *len) @@ -366,7 +380,7 @@ struct ndb_note *ndb_get_note_by_key(struct ndb_txn *txn, uint64_t key, size_t * return ndb_lookup_by_key(txn, key, NDB_DB_NOTE, len); } -struct ndb_note *ndb_get_profile_by_key(struct ndb_txn *txn, uint64_t key, size_t *len) +void *ndb_get_profile_by_key(struct ndb_txn *txn, uint64_t key, size_t *len) { return ndb_lookup_by_key(txn, key, NDB_DB_PROFILE, len); } diff --git a/nostrdb.h b/nostrdb.h @@ -166,6 +166,7 @@ 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); +uint64_t ndb_get_profilekey_by_pubkey(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 *);