diff --git a/kong/db/declarative/import.lua b/kong/db/declarative/import.lua index a9a222ee7a26..ab8ec84eb41d 100644 --- a/kong/db/declarative/import.lua +++ b/kong/db/declarative/import.lua @@ -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) diff --git a/kong/db/strategies/off/init.lua b/kong/db/strategies/off/init.lua index d3c8176c5519..5c4bcd8a0888 100644 --- a/kong/db/strategies/off/init.lua +++ b/kong/db/strategies/off/init.lua @@ -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