From 5a24c34f129aed7afce7ee63c44dcdec04874f9e Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Fri, 23 Apr 2021 16:13:39 +0200 Subject: [PATCH] DB: Add a macro to define the default 'iteration count' when no srv is available in the find commands --- inc/lektor/common.h | 3 +++ src/database/find.c | 15 +++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/inc/lektor/common.h b/inc/lektor/common.h index 1af96728..d26a4d40 100644 --- a/inc/lektor/common.h +++ b/inc/lektor/common.h @@ -126,6 +126,9 @@ void ___lkt_print(const char *section, const char *format, ...); #define LKT_DB_LANG "language" #define LKT_DB_ALL "string" +/* Default iteration count in search_iter */ +#define LKT_DB_DEFAULT_ITERATION_MAX 100 + #define LEKTOR_TAG_MAX 256 #define LKT_MESSAGE_ARGS_MAX 32 #define LKT_MESSAGE_MAX 2048 diff --git a/src/database/find.c b/src/database/find.c index a277c0cf..b2fe1eab 100644 --- a/src/database/find.c +++ b/src/database/find.c @@ -28,15 +28,15 @@ struct lkt_search { struct lkt_state *srv; size_t c; - long continuation; /* The continuation state of the client */ - int msg_count; /* How much messages we can send */ + long continuation; /* The continuation state of the client */ + int msg_count; /* How much messages we can send */ union { - struct lkt_sticker_opt st; /* Sticker construct structure */ - const char *plt_name; /* Playlist name */ + struct lkt_sticker_opt st; /* Sticker construct structure */ + const char *plt_name; /* Playlist name */ }; - struct lkt_uri ka_uri; /* Search by uri */ + struct lkt_uri ka_uri; /* Search by uri */ }; /* Getter functions */ @@ -75,9 +75,8 @@ database_search_free(struct lkt_search *search) struct lkt_search * database_search_new(struct lkt_state *srv, size_t c, int cont, function_ptr call) { -#pragma message(TODO "Use a macro to set the default line count per search") - /* Minus 3 for control messages. If no server do it 100 by 100, use a macro for that... */ - size_t msg_count = srv != NULL ? lkt_remaining_msg(srv, c) - 3 : 100; + /* Minus 3 for control messages. If no server do it `X` by `X`. */ + size_t msg_count = srv != NULL ? lkt_remaining_msg(srv, c) - 3 : LKT_DB_DEFAULT_ITERATION_MAX; struct lkt_search *ret_ptr = safe_malloc(sizeof(struct lkt_search)); struct lkt_search ret = { .srv = srv, -- GitLab