nostrdb

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

commit dba3acafc957766a7fe4dfcbc1b22a1eb661de43
parent 3cda40624b6236f32c95f06ebbaacb7a25ae71b2
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 30 Dec 2024 10:38:09 -0800

query: add missing since check to kind query

Diffstat:
Msrc/nostrdb.c | 10+++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -3343,7 +3343,7 @@ static int ndb_query_plan_execute_kinds(struct ndb_txn *txn, struct ndb_u64_ts tsid, *ptsid; struct ndb_filter_elements *kinds; struct ndb_query_result res; - uint64_t kind, note_id, until, *pint; + uint64_t kind, note_id, until, since, *pint; size_t note_size; int i, rc; @@ -3355,6 +3355,10 @@ static int ndb_query_plan_execute_kinds(struct ndb_txn *txn, if ((pint = ndb_filter_get_int(filter, NDB_FILTER_UNTIL))) until = *pint; + since = 0; + if ((pint = ndb_filter_get_int(filter, NDB_FILTER_SINCE))) + since = *pint; + db = txn->lmdb->dbs[NDB_DB_NOTE_KIND]; if ((rc = mdb_cursor_open(txn->mdb_txn, db, &cur))) @@ -3380,6 +3384,10 @@ static int ndb_query_plan_execute_kinds(struct ndb_txn *txn, if (ptsid->u64 != kind) break; + // don't continue the scan if we're below `since` + if (ptsid->timestamp < since) + break; + note_id = *(uint64_t*)v.mv_data; if (!(note = ndb_get_note_by_key(txn, note_id, &note_size))) goto next;