diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-23 11:37:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-23 11:37:55 +0000 |
commit | 79aac45aa30b25c61e13b75140ea4cd251d94378 (patch) | |
tree | f8ee8be464f0023fb25bdcb941015e85bc221c93 /src/plugins | |
parent | 782871dfcbb4324d96df4962dc821bc7378cf5c2 (diff) | |
parent | 46921bef90ac76c77953f435ef24bfc56275d9c3 (diff) | |
download | rspamd-79aac45aa30b25c61e13b75140ea4cd251d94378.tar.gz rspamd-79aac45aa30b25c61e13b75140ea4cd251d94378.zip |
Merge pull request #1451 from fatalbanana/redis
[Minor] Finally fix saving of URL tags
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/lua/url_tags.lua | 37 |
1 files 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 ]] |