From 47d53499e54c66e5acdf999c658689eb7f4b836c Mon Sep 17 00:00:00 2001 From: xumin Date: Thu, 21 Nov 2024 16:40:59 +0800 Subject: [PATCH] fix(dao): page size 1 does not work for lmdb Fix KAG-5875 --- kong/db/strategies/off/init.lua | 7 ++++++ .../04-admin_api/07-upstreams_routes_spec.lua | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/kong/db/strategies/off/init.lua b/kong/db/strategies/off/init.lua index a80772224f27..0f7d177dc7c3 100644 --- a/kong/db/strategies/off/init.lua +++ b/kong/db/strategies/off/init.lua @@ -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 diff --git a/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua b/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua index 8012e5d4d849..6f09e1572882 100644 --- a/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua +++ b/spec/02-integration/04-admin_api/07-upstreams_routes_spec.lua @@ -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()