From: Vsevolod Stakhov Date: Mon, 13 Jan 2020 09:41:52 +0000 (+0000) Subject: [Minor] Bayes_expiry: Test type before trying to evaluate X-Git-Tag: 2.3~121 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a0efb4c16292698298e787d07a6fe7ed1baa7c21;p=rspamd.git [Minor] Bayes_expiry: Test type before trying to evaluate Issue: #3208 --- 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