Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(utils): use kong.utils.table_merge implementation to replace kong.table.merge #9857

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kong/db/dao/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local log = ngx.log
local fmt = string.format
local match = string.match
local run_hook = hooks.run_hook
local table_merge = utils.table_merge


local ERR = ngx.ERR
Expand Down Expand Up @@ -156,7 +157,7 @@ local function get_pagination_options(self, options)
options = utils.deep_copy(options, false)

if type(options.pagination) == "table" then
options.pagination = utils.table_merge(self.pagination, options.pagination)
options.pagination = table_merge(self.pagination, options.pagination)

else
options.pagination = self.pagination
Expand Down
3 changes: 2 additions & 1 deletion kong/db/dao/targets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local ipairs = ipairs
local table = table
local type = type
local min = math.min
local table_merge = utils.table_merge


local _TARGETS = {}
Expand Down Expand Up @@ -197,7 +198,7 @@ function _TARGETS:page_for_upstream(upstream_pk, size, offset, options)
local pagination = self.pagination

if type(options) == "table" and type(options.pagination) == "table" then
pagination = utils.table_merge(pagination, options.pagination)
pagination = table_merge(pagination, options.pagination)
end

if not size then
Expand Down
3 changes: 2 additions & 1 deletion kong/db/strategies/postgres/connector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local fmt = string.format
local sub = string.sub
local utils_toposort = utils.topological_sort
local insert = table.insert
local table_merge = utils.table_merge


local WARN = ngx.WARN
Expand Down Expand Up @@ -1004,7 +1005,7 @@ function _M.new(kong_config)
end
end

local config_ro = utils.table_merge(config, ro_override)
local config_ro = table_merge(config, ro_override)

local sem
if config_ro.sem_max > 0 then
Expand Down
17 changes: 3 additions & 14 deletions kong/pdk/table.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local table_merge = require("kong.tools.utils").table_merge

--- Utilities for Lua tables.
--
-- @module kong.table
Expand Down Expand Up @@ -48,20 +50,7 @@ local clear_tab = require "table.clear"
-- local t1 = {1, 2, 3, foo = "f"}
-- local t2 = {4, 5, bar = "b"}
-- local t3 = kong.table.merge(t1, t2) -- {4, 5, 3, foo = "f", bar = "b"}
local function merge_tab(t1, t2)
local res = {}
if t1 then
for k,v in pairs(t1) do
res[k] = v
end
end
if t2 then
for k,v in pairs(t2) do
res[k] = v
end
end
return res
end
local merge_tab = table_merge


local function new(self)
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/opentelemetry/otlp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ local insert = table.insert
local tablepool_fetch = tablepool.fetch
local tablepool_release = tablepool.release
local deep_copy = utils.deep_copy
local table_merge = kong.table.merge
local shallow_copy = utils.shallow_copy
local table_merge = utils.table_merge
local getmetatable = getmetatable
local setmetatable = setmetatable

Expand Down
17 changes: 9 additions & 8 deletions kong/tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,17 @@ end
-- @param t2 The second table
-- @return The (new) merged table
function _M.table_merge(t1, t2)
if not t1 then
t1 = {}
local res = {}
vm-001 marked this conversation as resolved.
Show resolved Hide resolved
if t1 then
for k,v in pairs(t1) do
res[k] = v
end
end
if not t2 then
t2 = {}
if t2 then
for k,v in pairs(t2) do
res[k] = v
end
end

local res = {}
for k,v in pairs(t1) do res[k] = v end
for k,v in pairs(t2) do res[k] = v end
return res
end

Expand Down