Skip to content

Commit

Permalink
fix(incremental sync): fix cache_key handling for select_by_cache_key
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits committed Oct 31, 2024
1 parent 194bf88 commit 051fcb5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kong/db/declarative/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ local function _set_entity_for_txn(t, entity_name, item, options, is_delete)
if schema.cache_key then
local cache_key = dao:cache_key(item)

-- [[ TODO:
-- This part is used to add additional value of cache_key, we need to
-- make this code more stable, currently fixing is_consumer_in_group()
-- Note is_consumer_in_group() could not pass ws_id to construct cache_key,
-- so we need to set item.ws_id to nil firstly.
local ws_id = item.ws_id
item.ws_id = nil
cache_key = dao:cache_key(item)
t:set(cache_key, itm_value)
item.ws_id = ws_id
-- ]]

for _, wid in ipairs {ws_id, GLOBAL_WORKSPACE_TAG} do
local key = unique_field_key(entity_name, wid, "cache_key", cache_key)

Expand Down
9 changes: 9 additions & 0 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ local function select_by_field(self, field, value, options)
_, value = next(value)
end

-- [[ TODO:
-- This part is used to add additional value of cache_key, we need to
-- make this code more stable, currently fixing is_consumer_in_group()
if field == "cache_key" then
local cache_key = value
return select_by_key(schema, cache_key, false)
end
-- ]]

local ws_id = workspace_id(schema, options)

local key
Expand Down

0 comments on commit 051fcb5

Please sign in to comment.