From: Vsevolod Stakhov Date: Mon, 26 Feb 2018 11:33:26 +0000 (+0000) Subject: [Fix] Fix bayes schema conversion X-Git-Tag: 1.7.0~122 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39b50a5708cf8fa33c50f33bd63656da260d659e;p=thirdparty%2Frspamd.git [Fix] Fix bayes schema conversion --- diff --git a/lualib/lua_stat.lua b/lualib/lua_stat.lua index 5c7ca7f312..81b5d0ed82 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 5a42a8257d..3d3530b0cd 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")