From 9fe90fcd255b044358998355dea37d43c7136d57 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 4 Sep 2024 10:53:55 +0100 Subject: [PATCH] [Rework] Change the logic of skipping symbols We now do not skip pre/post filters even if the task result has reached threshold. --- src/libmime/lang_detection.c | 2 +- src/libserver/symcache/symcache_runtime.cxx | 43 ++++++++++++--------- src/libserver/symcache/symcache_runtime.hxx | 7 +++- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/libmime/lang_detection.c b/src/libmime/lang_detection.c index 4796e4834..6e180ea66 100644 --- a/src/libmime/lang_detection.c +++ b/src/libmime/lang_detection.c @@ -1828,7 +1828,7 @@ rspamd_language_detector_detect(struct rspamd_task *task, unsigned int cand_len; enum rspamd_language_category cat; struct rspamd_lang_detector_res *cand; - enum rspamd_language_detected_type r; + enum rspamd_language_detected_type r = rs_detect_none; struct rspamd_frequency_sort_cbdata cbd; /* Check if we have sorted candidates based on frequency */ gboolean frequency_heuristic_applied = FALSE, ret = FALSE, internal_heuristic_applied = FALSE; diff --git a/src/libserver/symcache/symcache_runtime.cxx b/src/libserver/symcache/symcache_runtime.cxx index dc7066b32..ddfbdf1ae 100644 --- a/src/libserver/symcache/symcache_runtime.cxx +++ b/src/libserver/symcache/symcache_runtime.cxx @@ -333,8 +333,8 @@ auto symcache_runtime::process_pre_postfilters(struct rspamd_task *task, */ if (stage != RSPAMD_TASK_STAGE_IDEMPOTENT && !(item->flags & SYMBOL_TYPE_IGNORE_PASSTHROUGH)) { - if (check_metric_limit(task)) { - msg_debug_cache_task_lambda("task has already the result being set, ignore further checks"); + if (check_process_status(task) == check_status::passthrough) { + msg_debug_cache_task_lambda("task has already the passthrough result being set, ignore further checks"); return true; } @@ -407,13 +407,20 @@ auto symcache_runtime::process_filters(struct rspamd_task *task, symcache &cache break; } + auto check_result = check_process_status(task); + if (!(item->flags & (SYMBOL_TYPE_FINE | SYMBOL_TYPE_IGNORE_PASSTHROUGH))) { - if (has_passtrough || check_metric_limit(task)) { - msg_debug_cache_task_lambda("task has already the result being set, ignore further checks"); + if (has_passtrough || check_result == check_status::passthrough) { + msg_debug_cache_task_lambda("task has already the passthrough result being set, ignore further checks"); has_passtrough = true; /* Skip this item */ continue; } + else if (check_result == check_status::limit_reached) { + msg_debug_cache_task_lambda("task has already the limit reached result being set, ignore further checks"); + /* Skip this item */ + continue; + } } auto dyn_item = &dynamic_items[idx]; @@ -531,19 +538,8 @@ auto symcache_runtime::process_symbol(struct rspamd_task *task, symcache &cache, return true; } -auto symcache_runtime::check_metric_limit(struct rspamd_task *task) -> bool +auto symcache_runtime::check_process_status(struct rspamd_task *task) -> symcache_runtime::check_status { - if (task->flags & RSPAMD_TASK_FLAG_PASS_ALL) { - return false; - } - - /* Check score limit */ - if (!std::isnan(lim)) { - if (task->result->score > lim) { - return true; - } - } - if (task->result->passthrough_result != nullptr) { /* We also need to check passthrough results */ auto *pr = task->result->passthrough_result; @@ -563,11 +559,22 @@ auto symcache_runtime::check_metric_limit(struct rspamd_task *task) -> bool } /* Immediately stop on non least passthrough action */ - return true; + return check_status::passthrough; } } - return false; + if (task->flags & RSPAMD_TASK_FLAG_PASS_ALL) { + return check_status::allow; + } + + /* Check score limit */ + if (!std::isnan(lim)) { + if (task->result->score > lim) { + return check_status::limit_reached; + } + } + + return check_status::allow; } auto symcache_runtime::check_item_deps(struct rspamd_task *task, symcache &cache, cache_item *item, diff --git a/src/libserver/symcache/symcache_runtime.hxx b/src/libserver/symcache/symcache_runtime.hxx index 7e4a41269..d1dc7ac24 100644 --- a/src/libserver/symcache/symcache_runtime.hxx +++ b/src/libserver/symcache/symcache_runtime.hxx @@ -60,6 +60,11 @@ class symcache_runtime { enabled = 1, disabled = 2, } slow_status; + enum class check_status { + allow, + limit_reached, + passthrough, + }; bool profile; double profile_start; @@ -77,7 +82,7 @@ class symcache_runtime { /* Specific stages of the processing */ auto process_pre_postfilters(struct rspamd_task *task, symcache &cache, int start_events, unsigned int stage) -> bool; auto process_filters(struct rspamd_task *task, symcache &cache, int start_events) -> bool; - auto check_metric_limit(struct rspamd_task *task) -> bool; + auto check_process_status(struct rspamd_task *task) -> check_status; auto check_item_deps(struct rspamd_task *task, symcache &cache, cache_item *item, cache_dynamic_item *dyn_item, bool check_only) -> bool; -- 2.39.5