diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-05-07 14:59:38 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-05-07 14:59:38 +0100 |
commit | 26689fd064825b8a31282a50c8b5d7eaefeaff10 (patch) | |
tree | 88b390dd93967a780c69be9d25ffa99552e78239 | |
parent | 691ec14cc2c40a5fb891d01de4358a3275722ad4 (diff) | |
download | rspamd-26689fd064825b8a31282a50c8b5d7eaefeaff10.tar.gz rspamd-26689fd064825b8a31282a50c8b5d7eaefeaff10.zip |
[Minor] Add hack to allow empty cache runtime for learning
-rw-r--r-- | src/libserver/symcache/symcache_c.cxx | 5 | ||||
-rw-r--r-- | src/libserver/symcache/symcache_impl.cxx | 12 | ||||
-rw-r--r-- | src/libstat/stat_process.c | 2 |
3 files changed, 15 insertions, 4 deletions
diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index d6e1bc6f2..12d888eb1 100644 --- a/src/libserver/symcache/symcache_c.cxx +++ b/src/libserver/symcache/symcache_c.cxx @@ -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); } diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx index fb274e080..f76188c9f 100644 --- a/src/libserver/symcache/symcache_impl.cxx +++ b/src/libserver/symcache/symcache_impl.cxx @@ -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; } diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index ac618770c..6683990c0 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -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", |