From 3c69fb32830fb2f6b9b06ad7ab2fead99278afc1 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sat, 21 Apr 2018 19:17:12 +0300 Subject: [PATCH] [Minor] Properly merge Redis hash into a table --- src/plugins/lua/bayes_expiry.lua | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/plugins/lua/bayes_expiry.lua b/src/plugins/lua/bayes_expiry.lua index 5a67bd90a..4f4d810bb 100644 --- a/src/plugins/lua/bayes_expiry.lua +++ b/src/plugins/lua/bayes_expiry.lua @@ -178,21 +178,15 @@ local expiry_script = [[ return res end - local function list2hash(list) - local res = {} + local function merge_list(table, list) local k for i, v in ipairs(list) do if i % 2 == 1 then k = v else - res[k] = v + table[k] = v end end - if not k then - return - else - return res - end end local expire = math.floor(KEYS[2]) @@ -297,8 +291,7 @@ local expiry_script = [[ local counters_key = pattern_sha1 .. '_counters' if cursor ~= 0 then - local counters = list2hash(redis.call('HGETALL', counters_key)) - if counters then c = counters end + merge_list(c, redis.call('HGETALL', counters_key)) end c.nelts = c.nelts + nelts -- 2.39.5