]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix processing of caches
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 10 Jan 2016 23:39:46 +0000 (23:39 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 10 Jan 2016 23:39:46 +0000 (23:39 +0000)
src/libstat/learn_cache/sqlite3_cache.c
src/libstat/stat_config.c
src/libstat/stat_internal.h
src/libstat/stat_process.c

index 6e040595de84d618bbef4d5633fbe3e253822275..4d97e308410526b514768bd380caff3e483cfea7 100644 (file)
@@ -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);
index 0ae36af1b5b7ab22b1b3a119d757aa34d63cdc7a..50897b082d4c300cd39071ff3711717473648e5e 100644 (file)
@@ -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",
index 52e3d728b432e8ffd3edbe0d8be763bc423ed8de..892da9e9d3c5a4b7c1351cbbe198675b3cd87601 100644 (file)
@@ -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;
 };
 
index 4bf99b98b2883130de348d161193fd3d499f0275..864336a614285d47968176edf078e5523397cc83 100644 (file)
@@ -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);