Skip to content

Commit

Permalink
query: add missing since check to kind query
Browse files Browse the repository at this point in the history
  • Loading branch information
jb55 committed Dec 30, 2024
1 parent 3cda406 commit dba3aca
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/nostrdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)))
Expand All @@ -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;
Expand Down

0 comments on commit dba3aca

Please sign in to comment.