nostrdb

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

commit 6fddb176492af955df0e9682b19cc2342efd93c3
parent 97faaec7b948da08780f836d61cb4c031eed2744
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  7 Feb 2024 16:18:33 -0800

query: include note size in query results

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

Diffstat:
Msrc/nostrdb.c | 19+++++++++++--------
Msrc/nostrdb.h | 1+
2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -2394,10 +2394,12 @@ static int compare_query_results(const void *pa, const void *pb) static void ndb_query_result_init(struct ndb_query_result *res, struct ndb_note *note, + uint64_t note_size, uint64_t note_id) { *res = (struct ndb_query_result){ .note_id = note_id, + .note_size = note_size, .note = note, }; } @@ -2425,6 +2427,7 @@ static int ndb_query_plan_execute_ids(struct ndb_txn *txn, struct ndb_query_result res; struct ndb_tsid tsid, *ptsid; uint64_t note_id, until, *pint; + uint64_t note_size; unsigned char *id; matched = 0; @@ -2463,7 +2466,7 @@ static int ndb_query_plan_execute_ids(struct ndb_txn *txn, continue; // get the note because we need it to match against the filter - if (!(note = ndb_get_note_by_key(txn, note_id, NULL))) + if (!(note = ndb_get_note_by_key(txn, note_id, &note_size))) continue; // Sure this particular lookup matched the index query, but @@ -2474,7 +2477,7 @@ static int ndb_query_plan_execute_ids(struct ndb_txn *txn, if (!ndb_filter_matches_with(filter, note, matched)) continue; - ndb_query_result_init(&res, note, note_id); + ndb_query_result_init(&res, note, note_size, note_id); if (!push_query_result(results, &res)) break; } @@ -2529,7 +2532,7 @@ static int ndb_query_plan_execute_tags(struct ndb_txn *txn, MDB_dbi db; MDB_val k, v; int len, taglen, rc, i; - uint64_t *pint, until, note_id; + uint64_t *pint, until, note_id, note_size; unsigned char key_buffer[255]; struct ndb_note *note; struct ndb_filter_elements *tags; @@ -2580,13 +2583,13 @@ static int ndb_query_plan_execute_tags(struct ndb_txn *txn, note_id = *(uint64_t*)v.mv_data; - if (!(note = ndb_get_note_by_key(txn, note_id, NULL))) + if (!(note = ndb_get_note_by_key(txn, note_id, &note_size))) continue; if (!ndb_filter_matches_with(filter, note, 1 << NDB_FILTER_TAGS)) goto next; - ndb_query_result_init(&res, note, note_id); + ndb_query_result_init(&res, note, note_size, note_id); if (!push_query_result(results, &res)) break; @@ -2612,7 +2615,7 @@ static int ndb_query_plan_execute_kinds(struct ndb_txn *txn, struct ndb_u64_tsid tsid, *ptsid; struct ndb_filter_elements *kinds; struct ndb_query_result res; - uint64_t kind, note_id, until, *pint; + uint64_t kind, note_id, note_size, until, *pint; int i, rc; // we should have kinds in a kinds filter! @@ -2649,13 +2652,13 @@ static int ndb_query_plan_execute_kinds(struct ndb_txn *txn, break; note_id = *(uint64_t*)v.mv_data; - if (!(note = ndb_get_note_by_key(txn, note_id, NULL))) + if (!(note = ndb_get_note_by_key(txn, note_id, &note_size))) goto next; if (!ndb_filter_matches_with(filter, note, 1 << NDB_FILTER_KINDS)) goto next; - ndb_query_result_init(&res, note, note_id); + ndb_query_result_init(&res, note, note_size, note_id); if (!push_query_result(results, &res)) break; diff --git a/src/nostrdb.h b/src/nostrdb.h @@ -407,6 +407,7 @@ struct ndb_block_iterator { struct ndb_query_result { struct ndb_note *note; + uint64_t note_size; uint64_t note_id; };