Skip to content

Commit ccb1c9e

Browse files
committed
perf(routing): eliminate closure allocation
1 parent e61f28c commit ccb1c9e

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

gateway/src/apicast/policy/routing/routing.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ function _M.new(config)
3737
return self
3838
end
3939

40+
local function route_upstream_usage_cleanup(self, usage, matched_rules)
41+
if not self.route_upstream then
42+
return
43+
end
44+
45+
local usage_diff = mapping_rules_matcher.clean_usage_by_owner_id(
46+
matched_rules , self.route_upstream:has_owner_id())
47+
usage:merge(usage_diff)
48+
end
49+
4050
function _M:access(context)
4151
-- All route definition needs to happen in the access phase to make sure that
4252
-- the mapping rule with the owner_id happens before the APIcast policy and
@@ -57,16 +67,7 @@ function _M:access(context)
5767

5868
-- this function substract the usage that does not match with the owner_id by
5969
-- the matched_rules
60-
context.route_upstream_usage_cleanup = function(self, usage, matched_rules)
61-
if not self.route_upstream then
62-
return
63-
end
64-
65-
local usage_diff = mapping_rules_matcher.clean_usage_by_owner_id(
66-
matched_rules , self.route_upstream:has_owner_id())
67-
usage:merge(usage_diff)
68-
end
69-
70+
context.route_upstream_usage_cleanup = route_upstream_usage_cleanup
7071
end
7172

7273

0 commit comments

Comments
 (0)