Skip to content

Commit

Permalink
refactor(dbless): clean logic of selec_by_field
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Oct 31, 2024
1 parent 8505300 commit 47bfed9
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,14 @@ local function select_by_field(self, field, value, options)
_, value = next(value)
end

local ws_id

if field == "cache_key" then
-- align with cache_key insertion logic in _set_entity_for_txn
ws_id = get_default_workspace()

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
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)

-- 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

0 comments on commit 47bfed9

Please sign in to comment.