]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Simplify scores check and extend it to pre/post filters
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 13 May 2022 20:20:20 +0000 (21:20 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 13 May 2022 20:20:20 +0000 (21:20 +0100)
src/libserver/symcache/symcache_runtime.cxx
src/libserver/symcache/symcache_runtime.hxx

index e5f93eb0dbca64f325b411e5f8a6d657f741594f..6c0af2b4728deae9dd03a59318dc309aed78906a 100644 (file)
@@ -51,6 +51,7 @@ symcache_runtime::create(struct rspamd_task *task, symcache &cache) -> symcache_
        ev_now_update_if_cheap(task->event_loop);
        ev_tstamp now = ev_now(task->event_loop);
        checkpoint->profile_start = now;
+       checkpoint->lim = rspamd_task_get_required_score(task, task->result);
 
        if ((cache.get_last_profile() == 0.0 || now > cache.get_last_profile() + PROFILE_MAX_TIME) ||
                (task->msg.len >= PROFILE_MESSAGE_SIZE_THRESHOLD) ||
@@ -319,6 +320,19 @@ symcache_runtime::process_pre_postfilters(struct rspamd_task *task,
        auto compare_functor = +[](int a, int b) { return a < b; };
 
        auto proc_func = [&](cache_item *item) {
+
+               /*
+                * We can safely ignore all pre/postfilters except idempotent ones and
+                * those that are marked as ignore passthrough result
+                */
+               if (stage != RSPAMD_TASK_STAGE_IDEMPOTENT &&
+                       !(item->flags & SYMBOL_TYPE_IGNORE_PASSTHROUGH)) {
+                       if (check_metric_limit(task)) {
+                               msg_info_task("task has already the result being set, ignore further checks");
+                               return false;
+                       }
+               }
+
                auto dyn_item = get_dynamic_item(item->id);
 
                if (!dyn_item->started && !dyn_item->finished) {
@@ -414,10 +428,7 @@ symcache_runtime::process_filters(struct rspamd_task *task, symcache &cache, int
 
                if (!(item->flags & SYMBOL_TYPE_FINE)) {
                        if (check_metric_limit(task)) {
-                               msg_info_task ("task has already scored more than %.2f, so do "
-                                                          "not "
-                                                          "plan more checks",
-                                               rs->score);
+                               msg_info_task("task has already the result being set, ignore further checks");
                                all_done = true;
                                break;
                        }
@@ -502,29 +513,12 @@ symcache_runtime::check_metric_limit(struct rspamd_task *task) -> bool
                return false;
        }
 
-       if (lim == 0.0) {
-               auto *res = task->result;
-
-               if (res) {
-                       auto ms = rspamd_task_get_required_score(task, res);
-
-                       if (!std::isnan(ms) && lim < ms) {
-                               rs = res;
-                               lim = ms;
-                       }
-               }
-       }
-
-       if (rs) {
-
-               if (rs->score > lim) {
+       /* Check score limit */
+       if (!std::isnan(lim)) {
+               if (task->result->score > lim) {
                        return true;
                }
        }
-       else {
-               /* No reject score define, always check all rules */
-               lim = -1;
-       }
 
        return false;
 }
index 3581a538358dc479ebdf50f3eafe7ce4e0389df6..237cad2d24a4069a9e273bdf66521d5219e7cebe 100644 (file)
@@ -54,8 +54,6 @@ class symcache_runtime {
        double profile_start;
        double lim;
 
-       struct ::rspamd_scan_result *rs;
-
        struct cache_dynamic_item *cur_item;
        order_generation_ptr order;
        /* Dynamically expanded as needed */