Skip to content

Commit 947c9fb

Browse files
committed
perf: reuse PolicyOrderChecker
1 parent 88df996 commit 947c9fb

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

gateway/src/apicast/policy_chain.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,25 @@ function _M.build_from_specs(policy_specs)
229229
return chain
230230
end
231231

232+
local function build_default_policy_order_checker()
233+
return PolicyOrderChecker.new(
234+
policy_manifests_loader.get_all()
235+
)
236+
end
237+
238+
--Cache for the PolicyOrderChecker instance (module-level, per-worker)
239+
-- Since manifests are static (only change on worker restart), we can safely
240+
-- cache the checker to avoid rebuilding OrderRestrictions on every call
241+
local default_order_checker = build_default_policy_order_checker()
242+
232243
-- Checks if there are any policies placed in the wrong place in the chain.
233244
-- It doesn't return anything, it prints error messages when there's a problem.
234245
function _M:check_order(manifests)
235-
PolicyOrderChecker.new(
236-
manifests or policy_manifests_loader.get_all()
237-
):check(self)
246+
-- If manifests are explicitly provided, create a new checker
247+
if manifests then
248+
return PolicyOrderChecker.new(manifests):check(self)
249+
end
250+
default_order_checker:check(self)
238251
end
239252

240253
local function call_chain(phase_name)

0 commit comments

Comments
 (0)