commit 26f96b8: [Fix] Increase/decrease hash_key value for tokens depending on is_unlearn

GitHub noreply at github.com
Mon Jul 29 17:55:47 UTC 2024


Author: aduernberger
Date: 2024-04-18 14:44:01 +0200
URL: https://github.com/rspamd/rspamd/commit/26f96b81fdf73a0bd4a663837ea4df496dcbbc14 (refs/pull/4930/head)

[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.
---
 lualib/redis_scripts/bayes_learn.lua | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lualib/redis_scripts/bayes_learn.lua b/lualib/redis_scripts/bayes_learn.lua
index 80d86d803..5456165b6 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


More information about the Commits mailing list