]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add hack to allow empty cache runtime for learning
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 13:59:38 +0000 (14:59 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 7 May 2022 13:59:38 +0000 (14:59 +0100)
src/libserver/symcache/symcache_c.cxx
src/libserver/symcache/symcache_impl.cxx
src/libstat/stat_process.c

index d6e1bc6f2233b8ee2525788180ac650d6a2c4094..12d888eb17180aa642a11e872fb3d7cd993a337e 100644 (file)
@@ -429,6 +429,11 @@ rspamd_symcache_is_symbol_enabled(struct rspamd_task *task,
        auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
        auto *real_cache = C_API_SYMCACHE(cache);
 
+       if (!cache_runtime) {
+               /* XXX: ugly hack to enable classification during learning... */
+               return TRUE;
+       }
+
        return cache_runtime->is_symbol_enabled(task, *real_cache, symbol);
 }
 
index fb274e08013a046afe91b66cf53f452785ef4414..f76188c9faad6d642c4f94fd30bf7fe7945a99b9 100644 (file)
@@ -20,6 +20,7 @@
 #include "symcache_runtime.hxx"
 #include "unix-std.h"
 #include "libutil/cxx/locked_file.hxx"
+#include "libutil/cxx/util.hxx"
 #include "fmt/core.h"
 #include "contrib/t1ha/t1ha.h"
 
@@ -424,7 +425,13 @@ auto symcache::add_dependency(int id_from, std::string_view to, int virtual_id_f
 
 auto symcache::resort() -> void
 {
-       auto ord = std::make_shared<order_generation>(filters.size(), cur_order_gen);
+       auto ord = std::make_shared<order_generation>(filters.size() +
+                       prefilters.size() +
+                       composites.size() +
+                       postfilters.size() +
+                       idempotent.size() +
+                       connfilters.size() +
+                       classifiers.size(), cur_order_gen);
 
        for (auto &it: filters) {
                if (it) {
@@ -585,8 +592,7 @@ auto symcache::resort() -> void
        append_items_vec(classifiers, ord->d);
 
        /* After sorting is done, we can assign all elements in the by_symbol hash */
-       for (auto i = 0; i < ord->size(); i++) {
-               const auto &it = ord->d[i];
+       for (const auto [i, it] : rspamd::enumerate(ord->d)) {
                ord->by_symbol[it->get_name()] = i;
                ord->by_cache_id[it->id] = i;
        }
index ac618770c6b6ecdb9afdeef8ae3160622a44ebff..6683990c06e40f0ee4bbc356c3b3a273ed0a9bf7 100644 (file)
@@ -320,7 +320,7 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx,
                        continue;
                }
 
-               if (!rspamd_symcache_is_symbol_enabled (task, task->cfg->cache,
+               if (!is_learn && !rspamd_symcache_is_symbol_enabled (task, task->cfg->cache,
                                st->stcf->symbol)) {
                        g_ptr_array_index (task->stat_runtimes, i) = NULL;
                        msg_debug_bayes ("symbol %s is disabled, skip classification",