Skip to content

Commit

Permalink
use tablepool
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Nov 5, 2024
1 parent 5b1a720 commit e25a188
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions kong/db/schema/others/declarative_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ local foreign_children = {}

do
local tb_nkeys = require("table.nkeys")
local tb_pool = require("tablepool")

-- Generate a stable and unique string key from primary key defined inside
-- schema, supports both non-composite and composite primary keys
Expand All @@ -52,7 +53,8 @@ do
return tostring(object[primary_key[1]])
end

local CACHED_OUT = {}
-- get a table for reuse purpose
local CACHED_OUT = tb_pool.fetch("dc_cached_pk", 2, 0)

-- The logic comes from get_cache_key_value(), which uses `id` directly to
-- extract foreign key.
Expand All @@ -68,7 +70,12 @@ do
insert(CACHED_OUT, tostring(v or ""))
end

return concat(CACHED_OUT, ":")
local str = concat(CACHED_OUT, ":")

-- releae table for next usage
tb_pool.release("dc_cached_pk", CACHED_OUT)

return str
end
end

Expand Down

0 comments on commit e25a188

Please sign in to comment.