]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix scripts invocation
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 15 Jan 2024 15:25:23 +0000 (15:25 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 15 Jan 2024 15:25:23 +0000 (15:25 +0000)
lualib/lua_bayes_redis.lua
src/libstat/learn_cache/redis_cache.cxx

index 3321c96c3c7ac9637766c34a2a09cb5c367a26f6..6f6c27403431e2b7e380f9a58d614cbc762d7996 100644 (file)
@@ -179,7 +179,7 @@ local function gen_cache_check_functor(redis_params, check_script_id)
       if err then
         callback(task, false, err)
       else
-        callback(task, true, data[1], data[2], data[3], data[4])
+        callback(task, true, tonumber(data))
       end
     end
 
@@ -190,20 +190,15 @@ local function gen_cache_check_functor(redis_params, check_script_id)
 end
 
 local function gen_cache_learn_functor(redis_params, learn_script_id)
-  return function(task, cache_id, callback)
+  return function(task, cache_id, is_spam)
     local function learn_redis_cb(err, data)
       lua_util.debugm(N, task, 'learn_cache redis cb: %s, %s', err, data)
-      if err then
-        callback(task, false, err)
-      else
-        callback(task, true)
-      end
     end
 
     lua_redis.exec_redis_script(learn_script_id,
         { task = task, is_write = true, key = cache_id },
         learn_redis_cb,
-        { cache_id })
+        { cache_id, is_spam and "1" or "0" })
 
   end
 end
index e53bd4df070e8aa86ce70909ed1a8c562ec51132..86a6a35d48136c8cb2f8a32eef690d3d3b54ab5e 100644 (file)
@@ -217,22 +217,28 @@ static gint
 rspamd_stat_cache_checked(lua_State *L)
 {
        auto *task = lua_check_task(L, 1);
-       auto val = lua_tointeger(L, 2);
-
-       if ((val > 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM)) ||
-               (val < 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_HAM))) {
-               /* Already learned */
-               msg_info_task("<%s> has been already "
-                                         "learned as %s, ignore it",
-                                         MESSAGE_FIELD(task, message_id),
-                                         (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM) ? "spam" : "ham");
-               task->flags |= RSPAMD_TASK_FLAG_ALREADY_LEARNED;
-       }
-       else if (val != 0) {
-               /* Unlearn flag */
-               task->flags |= RSPAMD_TASK_FLAG_UNLEARN;
+       auto res = lua_toboolean(L, 2);
+
+       if (res) {
+               auto val = lua_tointeger(L, 3);
+
+               if ((val > 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM)) ||
+                       (val < 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_HAM))) {
+                       /* Already learned */
+                       msg_info_task("<%s> has been already "
+                                                 "learned as %s, ignore it",
+                                                 MESSAGE_FIELD(task, message_id),
+                                                 (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM) ? "spam" : "ham");
+                       task->flags |= RSPAMD_TASK_FLAG_ALREADY_LEARNED;
+               }
+               else if (val != 0) {
+                       /* Unlearn flag */
+                       task->flags |= RSPAMD_TASK_FLAG_UNLEARN;
+               }
        }
 
+       /* Ignore errors for now, as we can do nothing about them at the moment */
+
        return 0;
 }