nostrdb

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

commit 8540083e16ffda95077fd44165d2476a569edd62
parent 0d88645985b2bb6a828c06b9708d608eaeb13739
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  5 Jan 2024 21:45:59 -0800

query: support until for kind query plans

Diffstat:
Mndb.c | 10++++++++--
Msrc/nostrdb.c | 8++++++--
2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/ndb.c b/ndb.c @@ -94,7 +94,7 @@ int ndb_print_kind_keys(struct ndb_txn *txn); static void print_note(struct ndb_note *note) { - printf("note[%d]: \"%s\"\n", ndb_note_kind(note), ndb_note_content(note)); + printf("note[%d-%d]: \"%s\"\n", ndb_note_kind(note), ndb_note_created_at(note), ndb_note_content(note)); } int main(int argc, char *argv[]) @@ -179,7 +179,7 @@ int main(int argc, char *argv[]) argv += 2; argc -= 2; - for (i = 0; argc && i < 2; i++) { + for (i = 0; argc && i < 3; i++) { if (!strcmp(argv[0], "-k")) { ndb_filter_start_field(f, NDB_FILTER_KINDS); ndb_filter_add_int_element(f, atoll(argv[1])); @@ -193,6 +193,12 @@ int main(int argc, char *argv[]) ndb_filter_end_field(f); argv += 2; argc -= 2; + } else if (!strcmp(argv[0], "-u")) { + ndb_filter_start_field(f, NDB_FILTER_UNTIL); + ndb_filter_add_int_element(f, atoll(argv[1])); + ndb_filter_end_field(f); + argv += 2; + argc -= 2; } } diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -2463,13 +2463,17 @@ 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; + uint64_t kind, note_id, until, *pint; int i, rc; // we should have kinds in a kinds filter! if (!(kinds = ndb_filter_get_elems(filter, NDB_FILTER_KINDS))) return 0; + until = UINT64_MAX; + if ((pint = ndb_filter_get_int(filter, NDB_FILTER_UNTIL))) + until = *pint; + db = txn->lmdb->dbs[NDB_DB_NOTE_KIND]; if ((rc = mdb_cursor_open(txn->mdb_txn, db, &cur))) @@ -2481,7 +2485,7 @@ static int ndb_query_plan_execute_kinds(struct ndb_txn *txn, kind = kinds->elements[i].integer; ndb_debug("kind %" PRIu64 "\n", kind); - ndb_u64_tsid_init(&tsid, kind, UINT64_MAX); + ndb_u64_tsid_init(&tsid, kind, until); k.mv_data = &tsid; k.mv_size = sizeof(tsid);