diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-10 23:39:46 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-10 23:39:46 +0000 |
commit | dd1af5b84e7bb401dbe9af004da9f4b49ed97b23 (patch) | |
tree | 289ec424f7e0add040971ccee52611bf1fb65697 | |
parent | 8bcc03ac88d6f99058bd1a6660f30cb535cf1515 (diff) | |
download | rspamd-dd1af5b84e7bb401dbe9af004da9f4b49ed97b23.tar.gz rspamd-dd1af5b84e7bb401dbe9af004da9f4b49ed97b23.zip |
Fix processing of caches
-rw-r--r-- | src/libstat/learn_cache/sqlite3_cache.c | 8 | ||||
-rw-r--r-- | src/libstat/stat_config.c | 13 | ||||
-rw-r--r-- | src/libstat/stat_internal.h | 4 | ||||
-rw-r--r-- | src/libstat/stat_process.c | 13 |
4 files changed, 26 insertions, 12 deletions
diff --git a/src/libstat/learn_cache/sqlite3_cache.c b/src/libstat/learn_cache/sqlite3_cache.c index 6e040595d..4d97e3084 100644 --- a/src/libstat/learn_cache/sqlite3_cache.c +++ b/src/libstat/learn_cache/sqlite3_cache.c @@ -179,7 +179,9 @@ rspamd_stat_cache_sqlite3_runtime (struct rspamd_task *task, gint rspamd_stat_cache_sqlite3_check (struct rspamd_task *task, - gboolean is_spam, gpointer c) + gboolean is_spam, + gpointer runtime, + gpointer c) { struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c; struct mime_text_part *part; @@ -240,7 +242,9 @@ rspamd_stat_cache_sqlite3_check (struct rspamd_task *task, gint rspamd_stat_cache_sqlite3_learn (struct rspamd_task *task, - gboolean is_spam, gpointer c) + gboolean is_spam, + gpointer runtime, + gpointer c) { struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c; gboolean unlearn = !!(task->flags & RSPAMD_TASK_FLAG_UNLEARN); diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 0ae36af1b..50897b082 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -182,11 +182,14 @@ 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); + /* XXX: bad hack to pass statfiles configuration to cache */ + if (cl->cache == NULL) { + cl->cache = rspamd_stat_get_cache (cache_name); + g_assert (cl->cache != NULL); + cl->cachecf = cl->cache->init (stat_ctx, cfg, st, cache_obj); + msg_debug_config ("added cache %s for symbol %s", + cl->cache->name, stf->symbol); + } if (st->bkcf == NULL) { msg_err_config ("cannot init backend %s for statfile %s", diff --git a/src/libstat/stat_internal.h b/src/libstat/stat_internal.h index 52e3d728b..892da9e9d 100644 --- a/src/libstat/stat_internal.h +++ b/src/libstat/stat_internal.h @@ -42,6 +42,8 @@ struct rspamd_statfile_runtime { struct rspamd_classifier { struct rspamd_stat_ctx *ctx; GArray *statfiles_ids; + struct rspamd_stat_cache *cache; + gpointer cachecf; gulong spam_learns; gulong ham_learns; struct rspamd_classifier_config *cfg; @@ -53,8 +55,6 @@ 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; }; diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 4bf99b98b..864336a61 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -376,6 +376,7 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx, { rspamd_learn_t learn_res = RSPAMD_LEARN_OK; struct rspamd_classifier *cl; + gpointer rt; guint i; /* Check whether we have learned that file */ @@ -389,8 +390,9 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx, } if (cl->cache && cl->cachecf) { - learn_res = cl->cache->process (task, spam, - cl->cachecf); + rt = cl->cache->runtime (task, cl->cachecf); + learn_res = cl->cache->check (task, spam, + cl->cachecf, rt); } if (learn_res == RSPAMD_LEARN_INGORE) { @@ -558,7 +560,7 @@ rspamd_stat_backends_post_learn (struct rspamd_stat_ctx *st_ctx, { struct rspamd_classifier *cl; struct rspamd_statfile *st; - gpointer bk_run; + gpointer bk_run, cache_run; guint i, j; gint id; gboolean res = TRUE; @@ -572,6 +574,11 @@ rspamd_stat_backends_post_learn (struct rspamd_stat_ctx *st_ctx, continue; } + if (cl->cache) { + cache_run = cl->cache->runtime (task, cl->cachecf); + cl->cache->learn (task, spam, cache_run, cl->cachecf); + } + for (j = 0; j < cl->statfiles_ids->len; j ++) { id = g_array_index (cl->statfiles_ids, gint, j); st = g_ptr_array_index (st_ctx->statfiles, id); |