diff --git a/kong/db/dao/init.lua b/kong/db/dao/init.lua index 65decd8c360e..cf317698652c 100644 --- a/kong/db/dao/init.lua +++ b/kong/db/dao/init.lua @@ -31,6 +31,10 @@ local DAO = {} DAO.__index = DAO +local DEFAULT_PAGE_SIZE = 100 +local MAX_PAGE_SIZE = 1000 + + local function page_iterator(pager, size, options) local page = 1 local i, rows, err, offset = 0, pager(size, nil, options) @@ -107,10 +111,10 @@ local function generate_foreign_key_methods(schema) error("size must be a positive number", 2) end - size = min(size, 1000) + size = min(size, MAX_PAGE_SIZE) else - size = 100 + size = DEFAULT_PAGE_SIZE end if offset ~= nil and type(offset) ~= "string" then @@ -155,10 +159,10 @@ local function generate_foreign_key_methods(schema) error("size must be a positive number", 2) end - size = min(size, 1000) + size = min(size, MAX_PAGE_SIZE) else - size = 100 + size = DEFAULT_PAGE_SIZE end local ok, errors = self.schema:validate_primary_key(foreign_key) @@ -358,13 +362,13 @@ end function DAO:page(size, offset, options) - size = tonumber(size == nil and 100 or size) + size = tonumber(size == nil and DEFAULT_PAGE_SIZE or size) if not size then error("size must be a number", 2) end - size = min(size, 1000) + size = min(size, MAX_PAGE_SIZE) if size < 0 then error("size must be positive (> 0)", 2) @@ -393,13 +397,13 @@ end function DAO:each(size, options) - size = tonumber(size == nil and 100 or size) + size = tonumber(size == nil and DEFAULT_PAGE_SIZE or size) if not size then error("size must be a number", 2) end - size = min(size, 1000) + size = min(size, MAX_PAGE_SIZE) if size < 0 then error("size must be positive (> 0)", 2) diff --git a/kong/db/strategies/postgres/init.lua b/kong/db/strategies/postgres/init.lua index 49865ceed86f..7fd8fdd0a9c5 100644 --- a/kong/db/strategies/postgres/init.lua +++ b/kong/db/strategies/postgres/init.lua @@ -20,7 +20,6 @@ local find = string.find local rep = string.rep local sub = string.sub local max = math.max -local min = math.min local log = ngx.log @@ -509,8 +508,6 @@ end local function page(self, size, token, foreign_key, foreign_entity_name) - size = min(size or 100, 1000) - local limit = size + 1 local statement_name