nostrdb

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

commit 97fa802f8142ba125d4ce17ba1c14c17ce821d2c
parent 3e6fa09993d20cca5b0c2e5b829903f81484413e
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  5 Feb 2024 16:48:36 -0800

ndb: add ndb_poll_for_notes

The polling variant of ndb_wait_for_notes. This makes more sense for
realtime apps like notedeck

Changelog-Added: Add ndb_poll_for_notes

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

diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -5615,6 +5615,20 @@ struct ndb_subscription *ndb_find_subscription(struct ndb *ndb, uint64_t subid) return sub; } +int ndb_poll_for_notes(struct ndb *ndb, uint64_t subid, uint64_t *note_ids, + int note_id_capacity) +{ + struct ndb_subscription *sub; + + if (subid == 0) + return 0; + + if (!(sub = ndb_find_subscription(ndb, subid))) + return 0; + + return prot_queue_try_pop_all(&sub->inbox, note_ids, note_id_capacity); +} + int ndb_wait_for_notes(struct ndb *ndb, uint64_t subid, uint64_t *note_ids, int note_id_capacity) { diff --git a/src/nostrdb.h b/src/nostrdb.h @@ -482,8 +482,8 @@ void ndb_filter_destroy(struct ndb_filter *); // SUBSCRIPTIONS uint64_t ndb_subscribe(struct ndb *, struct ndb_filter *, int num_filters); -int ndb_wait_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, - int note_id_capacity); +int ndb_wait_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, int note_id_capacity); +int ndb_poll_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids, int note_id_capacity); int ndb_unsubscribe(int subid); // FULLTEXT SEARCH