nostrdb: earlier since check in ndb_query_plan_execute_created_at

this avoids a lookup if we dont need it

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-12-13 20:56:26 -08:00
committed by Daniel D’Aquino
parent d24a3f0ce5
commit 2c4728508b

View File

@@ -3181,9 +3181,10 @@ static int ndb_query_plan_execute_created_at(struct ndb_txn *txn,
note_id = *(uint64_t*)v.mv_data;
assert(v.mv_size == 8);
// TODO(perf): if we are only looking for IDs and have no other
// condition, then we can use the ID in the index without
// looking up the note. For now we always look up the note
// don't continue the scan if we're below `since`
if (pkey->timestamp < since)
break;
if (!(note = ndb_get_note_by_key(txn, note_id, &note_size)))
goto next;
@@ -3191,10 +3192,6 @@ static int ndb_query_plan_execute_created_at(struct ndb_txn *txn,
if (!ndb_filter_matches_with(filter, note, 0))
goto next;
// don't continue the scan if we're below `since`
if (pkey->timestamp < since)
break;
ndb_query_result_init(&res, note, (uint64_t)note_size, note_id);
if (!push_query_result(results, &res))
break;