From 9f754e6c7738f2d0b136c07bf4ac8060888cb3b4 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 4 Dec 2023 15:18:50 +0000 Subject: [PATCH] [Project] Temporary fixes to start new bayes logic debug --- lualib/lua_bayes_redis.lua | 21 ++++++++++++++++++--- src/libstat/backends/redis_backend.c | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lualib/lua_bayes_redis.lua b/lualib/lua_bayes_redis.lua index 27d6c3e6f..5dca2db43 100644 --- a/lualib/lua_bayes_redis.lua +++ b/lualib/lua_bayes_redis.lua @@ -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 diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index 9263f479e..57cf059d8 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -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); -- 2.39.5