summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-12-08 10:48:53 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-12-08 10:48:53 +0000
commitcd568d70852da3d948783060d70bb3de531266e2 (patch)
tree17d97118918dd4a8fb8aeca7de07fa1e06adcf00
parent6c2f702ab403a74cf3f8738e671289c9bfed6602 (diff)
downloadrspamd-cd568d70852da3d948783060d70bb3de531266e2.tar.gz
rspamd-cd568d70852da3d948783060d70bb3de531266e2.zip
[Project] Various fixes
-rw-r--r--lualib/redis_scripts/bayes_classify.lua4
-rw-r--r--src/libstat/backends/redis_backend.cxx10
2 files changed, 9 insertions, 5 deletions
diff --git a/lualib/redis_scripts/bayes_classify.lua b/lualib/redis_scripts/bayes_classify.lua
index 9bef96f14..1a4734cf5 100644
--- a/lualib/redis_scripts/bayes_classify.lua
+++ b/lualib/redis_scripts/bayes_classify.lua
@@ -7,8 +7,8 @@ local prefix = KEYS[1]
local output_spam = {}
local output_ham = {}
-local learned_ham = redis.call('HGET', prefix, 'learns_ham') or 0
-local learned_spam = redis.call('HGET', prefix, 'learns_spam') or 0
+local learned_ham = tonumber(redis.call('HGET', prefix, 'learns_ham')) or 0
+local learned_spam = tonumber(redis.call('HGET', prefix, 'learns_spam')) or 0
local prefix_underscore = prefix .. '_'
-- Output is a set of pairs (token_index, token_count), tokens that are not
diff --git a/src/libstat/backends/redis_backend.cxx b/src/libstat/backends/redis_backend.cxx
index 2d548bf54..5d6a438d8 100644
--- a/src/libstat/backends/redis_backend.cxx
+++ b/src/libstat/backends/redis_backend.cxx
@@ -146,7 +146,7 @@ public:
}
for (auto [idx, val]: *results) {
- tok = (rspamd_token_t *) g_ptr_array_index(tokens, idx);
+ tok = (rspamd_token_t *) g_ptr_array_index(tokens, idx - 1);
tok->values[id] = val;
}
@@ -679,7 +679,7 @@ rspamd_redis_classified(lua_State *L)
rt->learned = learned;
redis_stat_runtime<float>::result_type *res;
- res = new redis_stat_runtime<float>::result_type(lua_objlen(L, tokens_pos));
+ res = new redis_stat_runtime<float>::result_type();
for (lua_pushnil(L); lua_next(L, tokens_pos); lua_pop(L, 1)) {
lua_rawgeti(L, -1, 1);
@@ -715,6 +715,9 @@ rspamd_redis_classified(lua_State *L)
filler_func(opposite_rt_maybe.value(), L, lua_tointeger(L, 4), 6);
}
+ /* Mark task as being processed */
+ task->flags |= RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS | RSPAMD_TASK_FLAG_HAS_HAM_TOKENS;
+
/* Process all tokens */
g_assert(rt->tokens != nullptr);
rt->process_tokens(rt->tokens);
@@ -747,13 +750,14 @@ rspamd_redis_process_tokens(struct rspamd_task *task,
if (!rt->need_redis_call) {
/* No need to do anything, as it is already done in the opposite class processing */
+ /* However, we need to store id as it is needed for further tokens processing */
+ rt->id = id;
return TRUE;
}
gsize tokens_len;
gchar *tokens_buf = rspamd_redis_serialize_tokens(task, tokens, &tokens_len);
-
rt->id = id;
lua_pushcfunction(L, &rspamd_lua_traceback);