]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Increase/decrease hash_key value for tokens depending on is_unlearn 4930/head
authoraduernberger <aduernberger@googlemail.com>
Thu, 18 Apr 2024 12:44:01 +0000 (14:44 +0200)
committerGitHub <noreply@github.com>
Thu, 18 Apr 2024 12:44:01 +0000 (14:44 +0200)
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

index 80d86d8036a4a1e40be04800ed96dc8074d65b4d..5456165b6949e55ed18e2dcb63d21f93880afa37 100644 (file)
@@ -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