]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Project] Temporary fixes to start new bayes logic debug
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 4 Dec 2023 15:18:50 +0000 (15:18 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 4 Dec 2023 15:18:50 +0000 (15:18 +0000)
lualib/lua_bayes_redis.lua
src/libstat/backends/redis_backend.c

index 27d6c3e6f562d180eb823be950adef2304075a7b..5dca2db430581004d5057c3f9773333b0b5b23b2 100644 (file)
@@ -19,15 +19,30 @@ limitations under the License.
 local exports = {}
 local lua_redis = require "lua_redis"
 local logger = require "rspamd_logger"
+local lua_util = require "lua_util"
+
+local N = "stat_redis"
 
 local function gen_classify_functor(redis_params, classify_script_id)
-  return function(task, expanded_key, stat_tokens)
-    -- TODO: write this function
+  return function(task, expanded_key, id, is_spam, stat_tokens, callback)
+
+    local function classify_redis_cb(err, data)
+      lua_util.debugm(N, task, 'classify redis cb: %s, %s', err, data)
+      if err then
+        callback(task, false, err)
+      else
+        callback(task, true, data[1], data[2], data[3])
+      end
+    end
+
+    lua_redis.exec_redis_script(classify_script_id,
+        { task = task, is_write = false, key = expanded_key },
+        classify_redis_cb, { expanded_key, stat_tokens })
   end
 end
 
 local function gen_learn_functor(redis_params, learn_script_id)
-  return function(task, expanded_key, stat_tokens)
+  return function(task, expanded_key, id, is_spam, stat_tokens, callback)
     -- TODO: write this function
   end
 end
index 9263f479e3b20eeba97c9741dff58b81d9e58c9a..57cf059d85c960f64fb2ed8f9d139fb7d5da1e15 100644 (file)
@@ -1248,12 +1248,14 @@ rspamd_redis_init(struct rspamd_stat_ctx *ctx,
        st_elt = g_malloc0(sizeof(*st_elt));
        st_elt->event_loop = ctx->event_loop;
        st_elt->ctx = backend;
+#if 0
        backend->stat_elt = rspamd_stat_ctx_register_async(
                rspamd_redis_async_stat_cb,
                rspamd_redis_async_stat_fin,
                st_elt,
                REDIS_STAT_TIMEOUT);
        st_elt->async = backend->stat_elt;
+#endif
 
        return (gpointer) backend;
 }
@@ -1284,6 +1286,7 @@ rspamd_redis_runtime(struct rspamd_task *task,
        rt->task = task;
        rt->ctx = ctx;
        rt->redis_object_expanded = object_expanded;
+       rt->stcf = stcf;
 
        rspamd_mempool_add_destructor(task->task_pool, rspamd_redis_fin, rt);
 
@@ -1382,6 +1385,7 @@ rspamd_redis_process_tokens(struct rspamd_task *task,
        gint err_idx = lua_gettop(L);
 
        /* Function arguments */
+       lua_rawgeti(L, LUA_REGISTRYINDEX, rt->ctx->cbref_classify);
        rspamd_lua_task_push(L, task);
        lua_pushstring(L, rt->redis_object_expanded);
        lua_pushinteger(L, id);