aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-13 09:41:52 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-13 09:41:52 +0000
commita0efb4c16292698298e787d07a6fe7ed1baa7c21 (patch)
tree6332f06001714184e1fc2e5671543461e573af4f /src/plugins
parent8a412222f3fe70d2ee6d2548f54d988444beb08a (diff)
downloadrspamd-a0efb4c16292698298e787d07a6fe7ed1baa7c21.tar.gz
rspamd-a0efb4c16292698298e787d07a6fe7ed1baa7c21.zip
[Minor] Bayes_expiry: Test type before trying to evaluate
Issue: #3208
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/lua/bayes_expiry.lua37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/plugins/lua/bayes_expiry.lua b/src/plugins/lua/bayes_expiry.lua
index e5eb471d4..6cdd1a059 100644
--- a/src/plugins/lua/bayes_expiry.lua
+++ b/src/plugins/lua/bayes_expiry.lua
@@ -259,23 +259,26 @@ local expiry_script = [[
0,0,0,0,0,0,0,0,0,0,0
for _,key in ipairs(keys) do
- local values = redis.call('HMGET', key, 'H', 'S')
- local ham = tonumber(values[1]) or 0
- local spam = tonumber(values[2]) or 0
- local ttl = redis.call('TTL', key)
- tokens[key] = {
- ham,
- spam,
- ttl
- }
- local total = spam + ham
- sum = sum + total
- sum_squares = sum_squares + total * total
- nelts = nelts + 1
-
- for k,v in pairs({['ham']=ham, ['spam']=spam, ['total']=total}) do
- if tonumber(v) > 19 then v = 20 end
- occurr[k][v] = occurr[k][v] and occurr[k][v] + 1 or 1
+ local t = redis.call('TYPE', key)
+ if t == 'hash' then
+ local values = redis.call('HMGET', key, 'H', 'S')
+ local ham = tonumber(values[1]) or 0
+ local spam = tonumber(values[2]) or 0
+ local ttl = redis.call('TTL', key)
+ tokens[key] = {
+ ham,
+ spam,
+ ttl
+ }
+ local total = spam + ham
+ sum = sum + total
+ sum_squares = sum_squares + total * total
+ nelts = nelts + 1
+
+ for k,v in pairs({['ham']=ham, ['spam']=spam, ['total']=total}) do
+ if tonumber(v) > 19 then v = 20 end
+ occurr[k][v] = occurr[k][v] and occurr[k][v] + 1 or 1
+ end
end
end