commit a0efb4c: [Minor] Bayes_expiry: Test type before trying to evaluate

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jan 13 09:49:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-01-13 09:41:52 +0000
URL: https://github.com/rspamd/rspamd/commit/a0efb4c16292698298e787d07a6fe7ed1baa7c21 (HEAD -> master)

[Minor] Bayes_expiry: Test type before trying to evaluate
Issue: #3208

---
 src/plugins/lua/bayes_expiry.lua | 37 ++++++++++++++++++++-----------------
 1 file 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
 


More information about the Commits mailing list