commit 26689fd: [Minor] Add hack to allow empty cache runtime for learning

Vsevolod Stakhov vsevolod at rspamd.com
Sat May 7 14:00:03 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-05-07 14:59:38 +0100
URL: https://github.com/rspamd/rspamd/commit/26689fd064825b8a31282a50c8b5d7eaefeaff10 (HEAD -> master)

[Minor] Add hack to allow empty cache runtime for learning

---
 src/libserver/symcache/symcache_c.cxx    |  5 +++++
 src/libserver/symcache/symcache_impl.cxx | 12 +++++++++---
 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",


More information about the Commits mailing list