From 39b50a5708cf8fa33c50f33bd63656da260d659e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 26 Feb 2018 11:33:26 +0000 Subject: [PATCH] [Fix] Fix bayes schema conversion --- lualib/lua_stat.lua | 24 +++++++++++++++--------- lualib/rspamadm/configwizard.lua | 3 ++- 2 files changed, 17 insertions(+), 10 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) diff --git a/lualib/rspamadm/configwizard.lua b/lualib/rspamadm/configwizard.lua index 5a42a8257..3d3530b0c 100644 --- a/lualib/rspamadm/configwizard.lua +++ b/lualib/rspamadm/configwizard.lua @@ -335,7 +335,8 @@ local function check_redis_classifier(cls, changes) '100d') expire = lua_util.parse_time_interval(expire) - if not lua_stat_tools.convert_bayes_schema(parsed_redis, symbol_spam, symbol_ham) then + if not lua_stat_tools.convert_bayes_schema(parsed_redis, symbol_spam, + symbol_ham, expire) then printf("Conversion failed") else printf("Conversion succeed") -- 2.39.5