Skip to content

Commit

Permalink
fix(dao): page size 1 does not work for lmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlightIbuki committed Nov 21, 2024
1 parent 9918f6d commit 47d5349
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ local function page_for_prefix(self, prefix, size, offset, options, follow)
return nil, err_or_more
end

-- special handling for page size 1.
-- drop other results
if size == 1 and size < res then
res = { res[1] }
err_or_more = true
end

local ret = {}
local ret_idx = 0
local schema = self.schema
Expand Down
23 changes: 23 additions & 0 deletions spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,29 @@ describe("Admin API: #" .. strategy, function()
assert.same({ data = {}, next = ngx.null }, json)
end)
end)

describe("#regression", function()
it("page size 1", function()
local res = assert(client:send {
method = "GET",
path = "/upstreams?size=1"
})
assert.response(res).has.status(200)
local json = assert.response(res).has.jsonbody()
assert.equal(1, #json.data)
assert.truthy(json.offset)

res = assert(client:send {
method = "GET",
path = "/upstreams",
query = {size = 1, offset = json.offset}
})
assert.response(res).has.status(200)
local json = assert.response(res).has.jsonbody()
assert.equal(1, #json.data)
assert.truthy(json.offset)
end)
end)
end)

describe("DELETE", function()
Expand Down

0 comments on commit 47d5349

Please sign in to comment.