From: aduernberger Date: Thu, 18 Apr 2024 12:44:01 +0000 (+0200) Subject: [Fix] Increase/decrease hash_key value for tokens depending on is_unlearn X-Git-Tag: 3.9.0~65^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4930%2Fhead;p=thirdparty%2Frspamd.git [Fix] Increase/decrease hash_key value for tokens depending on is_unlearn When relearning a message, this script is called twice: 1. With `is_unlearn` true and the old `is_spam` value 2. With `is_unlearn` false and the new `is_spam` value If `is_unlearn` is true, the code should not increase the value of the hash_key. Decreasing it ensures that it behaves like a fresh learn with the new is_spam value. --- diff --git a/lualib/redis_scripts/bayes_learn.lua b/lualib/redis_scripts/bayes_learn.lua index 80d86d8036..5456165b69 100644 --- a/lualib/redis_scripts/bayes_learn.lua +++ b/lualib/redis_scripts/bayes_learn.lua @@ -26,7 +26,7 @@ redis.call('HSET', prefix, 'version', '2') -- new schema redis.call('HINCRBY', prefix, learned_key, is_unlearn and -1 or 1) -- increase or decrease learned count for i, token in ipairs(input_tokens) do - redis.call('HINCRBY', token, hash_key, 1) + redis.call('HINCRBY', token, hash_key, is_unlearn and -1 or 1) if text_tokens then local tok1 = text_tokens[i * 2 - 1] local tok2 = text_tokens[i * 2] @@ -41,4 +41,4 @@ for i, token in ipairs(input_tokens) do redis.call('ZINCRBY', prefix .. '_z', is_unlearn and -1 or 1, token) end end -end \ No newline at end of file +end