nostrdb

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

commit 8698f4f8a385df97433f710d5fc3e0ae3cbd6cf7
parent 909e28338d405d3de8cbfc988a82b743c3f077c8
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  1 Aug 2024 13:38:26 -0700

debug: improve tag index display

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mndb.c | 5+++--
Msrc/nostrdb.c | 8+++-----
Msrc/print_util.h | 28++++++++++++++++++++++++++++
3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/ndb.c b/ndb.c @@ -1,6 +1,7 @@ #include "nostrdb.h" +#include "lmdb.h" #include "print_util.h" #include "hex.h" #include <time.h> @@ -97,7 +98,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 ndb_print_tag_keys(struct ndb_txn *txn); +int ndb_print_tag_index(struct ndb_txn *txn); static void print_note(struct ndb_note *note) { @@ -335,7 +336,7 @@ int main(int argc, char *argv[]) ndb_end_query(&txn); } else if (argc == 2 && !strcmp(argv[1], "print-tag-keys")) { ndb_begin_query(ndb, &txn); - ndb_print_tag_keys(&txn); + ndb_print_tag_index(&txn); ndb_end_query(&txn); } else if (argc == 3 && !strcmp(argv[1], "profile")) { pk_str = argv[2]; diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -5598,7 +5598,7 @@ void ndb_config_set_ingest_filter(struct ndb_config *config, config->filter_context = filter_ctx; } -int ndb_print_tag_keys(struct ndb_txn *txn) +int ndb_print_tag_index(struct ndb_txn *txn) { MDB_cursor *cur; MDB_val k, v; @@ -5609,10 +5609,8 @@ int ndb_print_tag_keys(struct ndb_txn *txn) i = 1; while (mdb_cursor_get(cur, &k, &v, MDB_NEXT) == 0) { - printf("%d note_tags '%.*s' %" PRIu64 "\n", - i, (int)k.mv_size-8, (const char *)k.mv_data, - *(uint64_t*)(k.mv_data+(k.mv_size-8))); - + printf("%d ", i); + print_tag_kv(txn, &k, &v); i++; } diff --git a/src/print_util.h b/src/print_util.h @@ -1,3 +1,5 @@ +#include "hex.h" +#include "lmdb.h" static void ndb_print_text_search_key(struct ndb_text_search_key *key) { @@ -14,6 +16,32 @@ static void print_hex(unsigned char* data, size_t size) { } } +static void print_tag_kv(struct ndb_txn *txn, MDB_val *k, MDB_val *v) +{ + char hex_id[65]; + struct ndb_note *note; + uint64_t ts; + + ts = *(uint64_t*)(k->mv_data+(k->mv_size-8)); + + // TODO: p tags, etc + if (((const char*)k->mv_data)[0] == 'e' && k->mv_size == (1 + 32 + 8)) { + printf("note_tags 'e"); + print_hex(k->mv_data+1, 32); + printf("' %" PRIu64, ts); + } else { + printf("note_tags '%.*s' %" PRIu64, (int)k->mv_size-8, + (const char *)k->mv_data, ts); + } + + ts = *(uint64_t*)v->mv_data; + + note = ndb_get_note_by_key(txn, ts, NULL); + assert(note); + hex_encode(ndb_note_id(note), 32, hex_id); + printf(" note_key:%" PRIu64 " id:%s\n", ts, hex_id); +} + static void print_hex_stream(FILE *stream, unsigned char* data, size_t size) { size_t i; for (i = 0; i < size; i++) {