From dba3acafc957766a7fe4dfcbc1b22a1eb661de43 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 30 Dec 2024 10:38:09 -0800 Subject: [PATCH] query: add missing since check to kind query --- src/nostrdb.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nostrdb.c b/src/nostrdb.c index 6b4f895..d41f23b 100644 --- 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, ¬e_size))) goto next;