summaryrefslogtreecommitdiffstats
path: root/lualib/lua_stat.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-26 11:33:26 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-26 11:33:26 +0000
commit39b50a5708cf8fa33c50f33bd63656da260d659e (patch)
treeeef1f87eda220a1cb621bf46e88cf28c098a1a18 /lualib/lua_stat.lua
parentf83fc39878f72945970f7b80795fcc7a68025a6b (diff)
downloadrspamd-39b50a5708cf8fa33c50f33bd63656da260d659e.tar.gz
rspamd-39b50a5708cf8fa33c50f33bd63656da260d659e.zip
[Fix] Fix bayes schema conversion
Diffstat (limited to 'lualib/lua_stat.lua')
-rw-r--r--lualib/lua_stat.lua24
1 files changed, 15 insertions, 9 deletions
diff --git a/lualib/lua_stat.lua b/lualib/lua_stat.lua
index 5c7ca7f31..81b5d0ed8 100644
--- a/lualib/lua_stat.lua
+++ b/lualib/lua_stat.lua
@@ -50,15 +50,21 @@ local nconverted = 0
for _,k in ipairs(keys) do
local elts = redis.call('HGETALL', k)
+ local neutral_prefix = string.gsub(k, KEYS[1], 'RS')
+ local real_key
+
+ for i,v in ipairs(elts) do
- for k,v in pairs(elts) do
- local neutral_prefix = string.gsub(k, KEYS[1], 'RS')
- local nkey = string.format('%s_%s', neutral_prefix, k)
- redis.call('HSET', nkey, KEYS[2], v)
- if KEYS[4] and tonumber(KEYS[3]) ~= 0 then
- redis.call('EXPIRE', nkey, KEYS[3])
+ if i % 2 ~= 0 then
+ real_key = v
+ else
+ local nkey = string.format('%s_%s', neutral_prefix, real_key)
+ redis.call('HSET', nkey, KEYS[2], v)
+ if KEYS[3] and tonumber(KEYS[3]) > 0 then
+ redis.call('EXPIRE', nkey, KEYS[3])
+ end
+ nconverted = nconverted + 1
end
- nconverted = nconverted + 1
end
end
@@ -70,7 +76,7 @@ return nconverted
ret, res = conn:exec()
if not ret then
- logger.errx('error converting symbol %s', symbol_spam)
+ logger.errx('error converting symbol %s: %s', symbol_spam, res)
return false
else
logger.messagex('converted %s elements from symbol %s', res, symbol_spam)
@@ -80,7 +86,7 @@ return nconverted
ret, res = conn:exec()
if not ret then
- logger.errx('error converting symbol %s', symbol_ham)
+ logger.errx('error converting symbol %s: %s', symbol_ham, res)
return false
else
logger.messagex('converted %s elements from symbol %s', res, symbol_ham)