From: Vsevolod Stakhov Date: Sat, 7 May 2022 13:59:38 +0000 (+0100) Subject: [Minor] Add hack to allow empty cache runtime for learning X-Git-Tag: 3.3~268 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=26689fd064825b8a31282a50c8b5d7eaefeaff10;p=thirdparty%2Frspamd.git [Minor] Add hack to allow empty cache runtime for learning --- diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index d6e1bc6f22..12d888eb17 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 fb274e0801..f76188c9fa 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(filters.size(), cur_order_gen); + auto ord = std::make_shared(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 ac618770c6..6683990c06 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",