nostrdb/filters: remove ndb_filter_group from public API
We can just use a list of filters instead when subscribing Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
Daniel D’Aquino
parent
6cd7b945ca
commit
8b03ed6175
@@ -35,6 +35,8 @@ static const int THREAD_QUEUE_BATCH = 4096;
|
|||||||
|
|
||||||
// maximum number of active subscriptions
|
// maximum number of active subscriptions
|
||||||
#define MAX_SUBSCRIPTIONS 32
|
#define MAX_SUBSCRIPTIONS 32
|
||||||
|
#define MAX_SCAN_CURSORS 12
|
||||||
|
#define MAX_FILTERS 16
|
||||||
|
|
||||||
// the maximum size of inbox queues
|
// the maximum size of inbox queues
|
||||||
static const int DEFAULT_QUEUE_SIZE = 1000000;
|
static const int DEFAULT_QUEUE_SIZE = 1000000;
|
||||||
@@ -175,6 +177,11 @@ struct ndb_ingester {
|
|||||||
ndb_ingest_filter_fn filter;
|
ndb_ingest_filter_fn filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ndb_filter_group {
|
||||||
|
struct ndb_filter *filters[MAX_FILTERS];
|
||||||
|
int num_filters;
|
||||||
|
};
|
||||||
|
|
||||||
struct ndb_subscription {
|
struct ndb_subscription {
|
||||||
uint64_t subid;
|
uint64_t subid;
|
||||||
struct ndb_filter_group group;
|
struct ndb_filter_group group;
|
||||||
@@ -213,7 +220,7 @@ struct ndb_scan_cursor {
|
|||||||
|
|
||||||
// same idea as DBScan in strfry
|
// same idea as DBScan in strfry
|
||||||
struct ndb_dbscan {
|
struct ndb_dbscan {
|
||||||
struct ndb_scan_cursor cursors[12];
|
struct ndb_scan_cursor cursors[MAX_SCAN_CURSORS];
|
||||||
int num_cursors;
|
int num_cursors;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -916,15 +923,15 @@ void ndb_filter_end_field(struct ndb_filter *filter)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ndb_filter_group_init(struct ndb_filter_group *group)
|
static void ndb_filter_group_init(struct ndb_filter_group *group)
|
||||||
{
|
{
|
||||||
group->num_filters = 0;
|
group->num_filters = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ndb_filter_group_add(struct ndb_filter_group *group,
|
static int ndb_filter_group_add(struct ndb_filter_group *group,
|
||||||
struct ndb_filter *filter)
|
struct ndb_filter *filter)
|
||||||
{
|
{
|
||||||
if (group->num_filters + 1 > NDB_MAX_FILTERS)
|
if (group->num_filters + 1 > MAX_FILTERS)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
group->filters[group->num_filters++] = filter;
|
group->filters[group->num_filters++] = filter;
|
||||||
@@ -5017,7 +5024,7 @@ int ndb_wait_for_notes(struct ndb *ndb, uint64_t subid, uint64_t *note_ids,
|
|||||||
return prot_queue_pop_all(&sub->inbox, note_ids, note_id_capacity);
|
return prot_queue_pop_all(&sub->inbox, note_ids, note_id_capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ndb_subscribe(struct ndb *ndb, struct ndb_filter_group *group)
|
uint64_t ndb_subscribe(struct ndb *ndb, struct ndb_filter *filters, int num_filters)
|
||||||
{
|
{
|
||||||
static uint64_t subids = 0;
|
static uint64_t subids = 0;
|
||||||
struct ndb_subscription *sub;
|
struct ndb_subscription *sub;
|
||||||
@@ -5036,7 +5043,11 @@ uint64_t ndb_subscribe(struct ndb *ndb, struct ndb_filter_group *group)
|
|||||||
subid = ++subids;
|
subid = ++subids;
|
||||||
sub->subid = subid;
|
sub->subid = subid;
|
||||||
|
|
||||||
memcpy(&sub->group, group, sizeof(*group));
|
ndb_filter_group_init(&sub->group);
|
||||||
|
for (index = 0; index < num_filters; index++) {
|
||||||
|
if (!ndb_filter_group_add(&sub->group, &filters[index]))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 500k ought to be enough for anyone
|
// 500k ought to be enough for anyone
|
||||||
buflen = sizeof(uint64_t) * 65536;
|
buflen = sizeof(uint64_t) * 65536;
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
|
|
||||||
// how many filters are allowed in a filter group
|
|
||||||
#define NDB_MAX_FILTERS 16
|
|
||||||
|
|
||||||
// maximum number of filters allowed in a filter group
|
// maximum number of filters allowed in a filter group
|
||||||
#define NDB_PACKED_STR 0x1
|
#define NDB_PACKED_STR 0x1
|
||||||
#define NDB_PACKED_ID 0x2
|
#define NDB_PACKED_ID 0x2
|
||||||
@@ -30,7 +27,6 @@ struct ndb_blocks;
|
|||||||
struct ndb_block;
|
struct ndb_block;
|
||||||
struct ndb_note;
|
struct ndb_note;
|
||||||
struct ndb_tag;
|
struct ndb_tag;
|
||||||
struct ndb_filter_group;
|
|
||||||
struct ndb_tags;
|
struct ndb_tags;
|
||||||
struct ndb_lmdb;
|
struct ndb_lmdb;
|
||||||
union ndb_packed_str;
|
union ndb_packed_str;
|
||||||
@@ -241,11 +237,6 @@ struct ndb_filter {
|
|||||||
struct ndb_filter_elements *elements[NDB_NUM_FILTERS];
|
struct ndb_filter_elements *elements[NDB_NUM_FILTERS];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ndb_filter_group {
|
|
||||||
struct ndb_filter *filters[NDB_MAX_FILTERS];
|
|
||||||
int num_filters;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ndb_config {
|
struct ndb_config {
|
||||||
int flags;
|
int flags;
|
||||||
int ingester_threads;
|
int ingester_threads;
|
||||||
@@ -470,12 +461,10 @@ int ndb_filter_start_generic_field(struct ndb_filter *, char tag);
|
|||||||
int ndb_filter_matches(struct ndb_filter *, struct ndb_note *);
|
int ndb_filter_matches(struct ndb_filter *, struct ndb_note *);
|
||||||
void ndb_filter_reset(struct ndb_filter *);
|
void ndb_filter_reset(struct ndb_filter *);
|
||||||
void ndb_filter_end_field(struct ndb_filter *);
|
void ndb_filter_end_field(struct ndb_filter *);
|
||||||
void ndb_filter_group_init(struct ndb_filter_group *group);
|
|
||||||
int ndb_filter_group_add(struct ndb_filter_group *group, struct ndb_filter *f);
|
|
||||||
void ndb_filter_destroy(struct ndb_filter *);
|
void ndb_filter_destroy(struct ndb_filter *);
|
||||||
|
|
||||||
// SUBSCRIPTIONS
|
// SUBSCRIPTIONS
|
||||||
uint64_t ndb_subscribe(struct ndb *, struct ndb_filter_group *);
|
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 ndb_wait_for_notes(struct ndb *, uint64_t subid, uint64_t *note_ids,
|
||||||
int note_id_capacity);
|
int note_id_capacity);
|
||||||
int ndb_unsubscribe(int subid);
|
int ndb_unsubscribe(int subid);
|
||||||
|
|||||||
Reference in New Issue
Block a user