]> source.dussan.org Git - rspamd.git/commitdiff
Increase revision after learning.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Jan 2015 15:01:32 +0000 (15:01 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Jan 2015 15:01:32 +0000 (15:01 +0000)
src/libstat/backends/backends.h
src/libstat/backends/mmaped_file.c
src/libstat/stat_config.c
src/libstat/stat_process.c

index d174756df0d9766c76b474df18898d6f7d878bf0..a3042e8a455fc44882c95f69da8b3dc00ad287de 100644 (file)
@@ -48,6 +48,7 @@ struct rspamd_stat_backend {
        gboolean (*learn_token)(struct token_node_s *tok,
                        struct rspamd_token_result *res, gpointer ctx);
        gulong (*total_learns)(struct rspamd_statfile_runtime *runtime, gpointer ctx);
+       gulong (*inc_learns)(struct rspamd_statfile_runtime *runtime, gpointer ctx);
        gpointer ctx;
 };
 
@@ -62,5 +63,7 @@ gboolean rspamd_mmaped_file_learn_token (struct token_node_s *tok,
                gpointer ctx);
 gulong rspamd_mmaped_file_total_learns (struct rspamd_statfile_runtime *runtime,
                gpointer ctx);
+gulong rspamd_mmaped_file_inc_learns (struct rspamd_statfile_runtime *runtime,
+               gpointer ctx);
 
 #endif /* BACKENDS_H_ */
index 8965353a138e67412af0c0ddbba084fbca234baa..e85db248bdf8bf9f52230be731b7b48e3c663c96 100644 (file)
@@ -956,3 +956,19 @@ rspamd_mmaped_file_total_learns (struct rspamd_statfile_runtime *runtime,
 
        return rev;
 }
+
+gulong
+rspamd_mmaped_file_inc_learns (struct rspamd_statfile_runtime *runtime,
+               gpointer ctx)
+{
+       rspamd_mmaped_file_t *mf = (rspamd_mmaped_file_t *)runtime;
+       guint64 rev = 0;
+       time_t t;
+
+       if (mf != NULL) {
+               rspamd_mmaped_file_inc_revision (mf);
+               rspamd_mmaped_file_get_revision (mf, &rev, &t);
+       }
+
+       return rev;
+}
index a214710f28db22fc8deda913a9fae3f7591b752a..7d24be267c933c1da1bccb2aea8cb4fbda5e969b 100644 (file)
@@ -50,8 +50,9 @@ struct rspamd_stat_backend stat_backends[] = {
                .init = rspamd_mmaped_file_init,
                .runtime = rspamd_mmaped_file_runtime,
                .process_token = rspamd_mmaped_file_process_token,
+               .learn_token = rspamd_mmaped_file_learn_token,
                .total_learns = rspamd_mmaped_file_total_learns,
-               .learn_token = rspamd_mmaped_file_learn_token
+               .inc_learns = rspamd_mmaped_file_inc_learns
        }
 };
 
index cdf45a80a4fc54b3a55f7367d6b88f1ab28e849d..b0e8ffdb9cdb3f495ea7f41d205b4d743ff8bb2e 100644 (file)
@@ -446,11 +446,13 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L,
        struct rspamd_stat_ctx *st_ctx;
        struct rspamd_tokenizer_runtime *tklist = NULL, *tok;
        struct rspamd_classifier_runtime *cl_run;
+       struct rspamd_statfile_runtime *st_run;
        struct classifier_ctx *cl_ctx;
        struct preprocess_cb_data cbdata;
        GList *cl_runtimes;
-       GList *cur;
+       GList *cur, *curst;
        gboolean ret = FALSE;
+       gulong nrev;
 
        st_ctx = rspamd_stat_get_ctx ();
        g_assert (st_ctx != NULL);
@@ -509,6 +511,19 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L,
                                        g_tree_foreach (cl_run->tok->tokens, rspamd_stat_learn_token,
                                                        &cbdata);
 
+                                       curst = g_list_first (cl_run->st_runtime);
+
+                                       while (curst) {
+                                               st_run = (struct rspamd_statfile_runtime *)curst->data;
+
+                                               nrev = st_run->backend->inc_learns (st_run->backend_runtime,
+                                                               st_run->backend->ctx);
+
+                                               msg_debug ("learned %s, new revision: %ul",
+                                                               st_run->st->symbol, nrev);
+
+                                               curst = g_list_next (curst);
+                                       }
                                }
                                else {
                                        return FALSE;