From 46921bef90ac76c77953f435ef24bfc56275d9c3 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Thu, 23 Feb 2017 13:02:46 +0200 Subject: [PATCH] [Minor] Finally fix saving of URL tags --- src/plugins/lua/url_tags.lua | 37 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/plugins/lua/url_tags.lua b/src/plugins/lua/url_tags.lua index 7dcd453e1..4718d23d2 100644 --- a/src/plugins/lua/url_tags.lua +++ b/src/plugins/lua/url_tags.lua @@ -88,41 +88,42 @@ local redis_set_script_head = 'local expiry = ' local redis_set_script_tail = [[ local now = math.floor(table.remove(ARGV)) local res = redis.call('MGET', unpack(KEYS)) +local data = {} for i = 1, #res do - local tmp1, tmp2, metatags = {}, {}, {} - if res[i] then + local which = KEYS[i] + if type(res[i]) == 'string' then + data[which] = {} for goo in string.gmatch(res[i], '[^/]+') do + local metatags = {} local time, tag, meta = string.match(goo, '(%d+)|([^|]+)|(.+)') if (time + expiry) > now then for m in string.gmatch(meta, '[^,]+') do metatags[m] = true end - tmp1[tag] = {time, metatags} + data[which][tag] = {time, metatags} end end end - local idx = string.find(ARGV[i], '|') - if not idx then - return redis.error_reply('bad arguments') - end - local t = string.sub(ARGV[i], 1, idx - 1) - local m_str = string.sub(ARGV[i], idx + 1) - if not tmp1[t] then - tmp1[t] = {now, {}} - else - tmp1[t][1] = now - end - for mt in string.gmatch(m_str, '[^,]+') do - tmp1[t][2][mt] = true + for goo in string.gmatch(ARGV[i], '[^/]+') do + local metatags = {} + if not data[which] then + data[which] = {} + end + local tag, meta = string.match(goo, '([^|]+)|(.+)') + for m in string.gmatch(meta, '[^,]+') do + metatags[m] = true + end + data[which][tag] = {now, metatags} end - for k, v in pairs(tmp1) do + local tmp2 = {} + for k, v in pairs(data[which]) do local meta_list = {} for kk in pairs(v[2]) do table.insert(meta_list, kk) end table.insert(tmp2, v[1] .. '|' .. k .. '|' .. table.concat(meta_list, ',')) end - redis.call('SETEX', KEYS[i], expiry, table.concat(tmp2, '/')) + redis.call('SETEX', which, expiry, table.concat(tmp2, '/')) end ]] -- 2.39.5