From 8bcc03ac88d6f99058bd1a6660f30cb535cf1515 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 10 Jan 2016 23:27:51 +0000 Subject: [PATCH] Fix caches initialization. --- src/libstat/stat_config.c | 14 ++++++++++---- src/libstat/stat_internal.h | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index d8b980aec..0ae36af1b 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -165,9 +165,10 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base) } } - cl->cache = rspamd_stat_get_cache (cache_name); - g_assert (cl->cache != NULL); - cl->cachecf = cl->cache->init (stat_ctx, cfg, cache_obj); + if (cache_name == NULL) { + /* We assume that learn cache is the same as backend */ + cache_name = clf->backend; + } curst = clf->statfiles; @@ -181,6 +182,12 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base) msg_debug_config ("added backend %s for symbol %s", bk->name, stf->symbol); + st->cache = rspamd_stat_get_cache (cache_name); + g_assert (st->cache != NULL); + st->cachecf = st->cache->init (stat_ctx, cfg, st, cache_obj); + msg_debug_config ("added cache %s for symbol %s", + st->cache->name, stf->symbol); + if (st->bkcf == NULL) { msg_err_config ("cannot init backend %s for statfile %s", clf->backend, stf->symbol); @@ -363,7 +370,6 @@ rspamd_stat_ctx_register_async (rspamd_stat_async_handler handler, { struct rspamd_stat_async_elt *elt; struct rspamd_stat_ctx *st_ctx; - gdouble jittered_time; st_ctx = rspamd_stat_get_ctx (); g_assert (st_ctx != NULL); diff --git a/src/libstat/stat_internal.h b/src/libstat/stat_internal.h index 7a3951a0e..52e3d728b 100644 --- a/src/libstat/stat_internal.h +++ b/src/libstat/stat_internal.h @@ -41,8 +41,6 @@ struct rspamd_statfile_runtime { /* Common classifier structure */ struct rspamd_classifier { struct rspamd_stat_ctx *ctx; - struct rspamd_stat_cache *cache; - gpointer cachecf; GArray *statfiles_ids; gulong spam_learns; gulong ham_learns; @@ -55,6 +53,8 @@ struct rspamd_statfile { struct rspamd_statfile_config *stcf; struct rspamd_classifier *classifier; struct rspamd_stat_backend *backend; + struct rspamd_stat_cache *cache; + gpointer cachecf; gpointer bkcf; }; -- 2.39.5