Copilot commented on code in PR #13757:
URL: https://github.com/apache/apisix/pull/13757#discussion_r3679932509
##########
apisix/plugin.lua:
##########
@@ -818,7 +818,10 @@ local function merge_consumer_route(route_conf,
consumer_conf, consumer_group_co
return route_conf
end
- local new_route_conf = core.table.deepcopy(route_conf)
+ -- the plugins subtree is fully overwritten below, so there is no need to
+ -- deep-copy it; shallow-copy that subtree to avoid the wasted work
+ local new_route_conf = core.table.deepcopy(route_conf,
+ { shallow_prefix = "self.value.plugins" })
Review Comment:
The new deepcopy option here is not just an optimization: the comment says
the plugins subtree is "fully overwritten" and implies deep-copy is
unnecessary, but the key reason is preserving plugin-conf identity (cached
state) while still copying the `plugins` container table so overwrites don’t
mutate the original route config.
##########
apisix/core/table.lua:
##########
@@ -130,7 +131,8 @@ do
copied[orig] = copy
for orig_key, orig_value in pairs(orig) do
local path = parent .. "." .. tostring(orig_key)
- if opts and array_find(opts.shallows, path) then
+ if opts and (array_find(opts.shallows, path) or
+ (opts.shallow_prefix and str_has_prefix(parent,
opts.shallow_prefix))) then
copy[orig_key] = orig_value
Review Comment:
`shallow_prefix` matching uses a raw string prefix (`has_prefix(parent,
shallow_prefix)`), which can unintentionally match sibling paths like
`self.value.plugins2` when `shallow_prefix` is `self.value.plugins`. Also,
`core.string.has_prefix` throws if `shallow_prefix` is not a string, while
`opts.shallows` is currently tolerant of wrong types; the new option should be
similarly defensive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]