Skip to content

Commit

Permalink
dbChannel: search for the ts filter on init instead of on first use
Browse files Browse the repository at this point in the history
  • Loading branch information
exzombie committed Apr 20, 2023
1 parent 4bde113 commit 3bcdd33
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions modules/database/src/ioc/db/dbChannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct parseContext {

static void *dbChannelFreeList;
static void *chFilterFreeList;
static int tsFilterRegistered;

void dbChannelExit(void)
{
Expand All @@ -67,6 +68,8 @@ void dbChannelInit (void)
freeListInitPvt(&dbChannelFreeList, sizeof(dbChannel), 128);
freeListInitPvt(&chFilterFreeList, sizeof(chFilter), 64);
db_init_event_freelists();

tsFilterRegistered = dbFindFilter("ts", 2) != NULL;
}

static void chf_value(parseContext *parser, parse_result *presult)
Expand Down Expand Up @@ -461,18 +464,12 @@ dbChannel * dbChannelCreate(const char *name)
field and replace the field with a channel filter string. */
{
static char const tsfilter[] = ".{\"ts\":{\"num\":\"dbl\"}}";
static int exists_ts = -1;

size_t namelen = strlen(name);
int reclen = namelen - sizeof(".TIME") + 1;
int has_time = reclen > 0 && !strcmp(name + reclen, ".TIME");

if (exists_ts == -1) {
/* Only look for the filter on first use. */
exists_ts = dbFindFilter("ts", 2) != NULL;
}

if (has_time && exists_ts) {
if (has_time && tsFilterRegistered) {
cname = malloc(reclen + strlen(tsfilter) + 1);
if (!cname)
goto finish;
Expand Down Expand Up @@ -800,10 +797,16 @@ void dbRegisterFilter(const char *name, const chFilterIf *fif, void *puser)

const chFilterPlugin * dbFindFilter(const char *name, size_t len)
{
GPHENTRY *pgph = gphFindParse(pdbbase->pgpHash, name, len,
&pdbbase->filterList);
GPHENTRY *pgph;

if (!name || !len || !*name || !pdbbase)
return NULL;

pgph = gphFindParse(pdbbase->pgpHash, name, len,
&pdbbase->filterList);

if (!pgph)
return NULL;

return (chFilterPlugin *) pgph->userPvt;
}

0 comments on commit 3bcdd33

Please sign in to comment.