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(dbless): clean logic of select_by_field #13817

Merged
merged 2 commits into from
Oct 31, 2024
Merged
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
23 changes: 8 additions & 15 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,16 @@ local function select_by_field(self, field, value, options)
_, value = next(value)
end

local ws_id
local schema_field = schema.fields[field]
local unique_across_ws = schema_field and schema_field.unique_across_ws

if field == "cache_key" then
-- align with cache_key insertion logic in _set_entity_for_txn
ws_id = get_default_workspace()
-- only accept global query by field if field is unique across workspaces
assert(not options or options.workspace ~= null or unique_across_ws)

else
ws_id = workspace_id(schema, options)

local unique_across_ws = schema.fields[field].unique_across_ws
-- only accept global query by field if field is unique across workspaces
assert(not options or options.workspace ~= null or unique_across_ws)

if unique_across_ws then
ws_id = get_default_workspace()
end
end
-- align with cache_key insertion logic in _set_entity_for_txn
local ws_id = (unique_across_ws or field == "cache_key") and
get_default_workspace() or
workspace_id(schema, options)

local key = unique_field_key(schema.name, ws_id, field, value)

Expand Down
Loading