]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Change the logic of skipping symbols 5126/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 4 Sep 2024 09:53:55 +0000 (10:53 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 4 Sep 2024 09:53:55 +0000 (10:53 +0100)
We now do not skip pre/post filters even if the task result has reached
threshold.

src/libmime/lang_detection.c
src/libserver/symcache/symcache_runtime.cxx
src/libserver/symcache/symcache_runtime.hxx

index 4796e4834d7d22927e392ed55f368aa76ae49541..6e180ea6642d52330b205dc2434d59d0aac3a492 100644 (file)
@@ -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;
index dc7066b32b0639e808a7573123b599365e50ce42..ddfbdf1ae4976d4b057674e085c15bd664b9e7e0 100644 (file)
@@ -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,
index 7e4a4126956d5d0e1cf1e5c0627da81526f2ffe2..d1dc7ac2472894d6c0ab110fd50337ab52ae2398 100644 (file)
@@ -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;