nostrdb

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

commit b9a7ab3ea34be2dd1f0a841aee00d656a2c8cf5f
parent c1425ad0b650e7a5e2cec6f8af8474df7001b387
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  5 Jan 2024 20:40:14 -0800

debug: add print_kind_keys helper

I needed this for debugging kind queries

Diffstat:
Mndb.c | 5+++++
Msrc/nostrdb.c | 22++++++++++++++++++++++
Mtest.c | 1+
3 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/ndb.c b/ndb.c @@ -89,6 +89,7 @@ static void print_stats(struct ndb_stat *stat) } int ndb_print_search_keys(struct ndb_txn *txn); +int ndb_print_kind_keys(struct ndb_txn *txn); int main(int argc, char *argv[]) { @@ -177,6 +178,10 @@ int main(int argc, char *argv[]) ndb_begin_query(ndb, &txn); ndb_print_search_keys(&txn); ndb_end_query(&txn); + } else if (argc == 2 && !strcmp(argv[1], "print-kind-keys")) { + ndb_begin_query(ndb, &txn); + ndb_print_kind_keys(&txn); + ndb_end_query(&txn); } else { return usage(); } diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -5011,6 +5011,28 @@ void ndb_config_set_ingest_filter(struct ndb_config *config, config->filter_context = filter_ctx; } +int ndb_print_kind_keys(struct ndb_txn *txn) +{ + MDB_cursor *cur; + MDB_val k, v; + int i; + struct ndb_u64_tsid *tsid; + + if (mdb_cursor_open(txn->mdb_txn, txn->lmdb->dbs[NDB_DB_NOTE_KIND], &cur)) + return 0; + + i = 1; + while (mdb_cursor_get(cur, &k, &v, MDB_NEXT) == 0) { + tsid = k.mv_data; + printf("%d note_kind %" PRIu64 " %" PRIu64 "\n", + i, tsid->u64, tsid->timestamp); + + i++; + } + + return 1; +} + // used by ndb.c int ndb_print_search_keys(struct ndb_txn *txn) { diff --git a/test.c b/test.c @@ -19,6 +19,7 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +int ndb_print_kind_keys(struct ndb_txn *txn); static const char *test_dir = "./testdata/db"; static NdbProfile_table_t lookup_profile(struct ndb_txn *txn, uint64_t pk)