]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Various fixes
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 8 Dec 2023 10:48:53 +0000 (10:48 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 8 Dec 2023 10:48:53 +0000 (10:48 +0000)
lualib/redis_scripts/bayes_classify.lua
src/libstat/backends/redis_backend.cxx

index 9bef96f145fd90371ed145f24656905a68476f6a..1a4734cf5d21c0991e4c5ef42e982152b921a6f7 100644 (file)
@@ -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
index 2d548bf54fcee40fe0d62045a01b1763a1fe16fc..5d6a438d8cf7ba4f2730ecac0bdc391de106fe4b 100644 (file)
@@ -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);