From 4203d8caf65bf84106cd26bd5c058e6610ddeaf6 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 19 Aug 2018 11:55:35 +0100 Subject: [PATCH] [Minor] Combine selectors and use the proper table field in ratelimit --- src/plugins/lua/ratelimit.lua | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index d9c0f164e..8c0c48387 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -432,25 +432,37 @@ end local function limit_to_prefixes(task, k, v, prefixes) local n = 0 - for _,bucket in ipairs(v.bucket) do - local prefix + for _,bucket in ipairs(v.buckets) do if v.selector then - prefix = lua_selectors.process_selectors(task, v.selector) + local selectors = lua_selectors.process_selectors(task, v.selector) + if selectors then + local combined = lua_selectors.combine_selectors(task, selectors, ':') + if type(combined) == 'string' then + prefixes[combined] = make_prefix(combined, k, bucket) + n = n + 1 + else + fun.each(function(p) + prefixes[p] = make_prefix(p, k, bucket) + n = n + 1 + end, combined) + end + end else - prefix = gen_rate_key(task, k, bucket) - end - - if prefix then - if type(prefix) == 'string' then - prefixes[prefix] = make_prefix(prefix, k, bucket) - n = n + 1 - else - fun.each(function(p) - prefixes[p] = make_prefix(p, k, bucket) + local prefix = gen_rate_key(task, k, bucket) + if prefix then + if type(prefix) == 'string' then + prefixes[prefix] = make_prefix(prefix, k, bucket) n = n + 1 - end, prefix) + else + fun.each(function(p) + prefixes[p] = make_prefix(p, k, bucket) + n = n + 1 + end, prefix) + end end end + + end return n -- 2.39.5