Skip to content

Commit

Permalink
refactor(db) define default/max page sizes as constants
Browse files Browse the repository at this point in the history
From #3723
  • Loading branch information
thibaultcha authored Aug 23, 2018
1 parent be50425 commit 4043aa7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 12 additions & 8 deletions kong/db/dao/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions kong/db/strategies/postgres/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4043aa7

Please sign in to comment.