From 97bd6b2cedb3724280778d9916defa9755754904 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 26 Nov 2024 10:51:59 +0800 Subject: [PATCH] plugin test --- kong/db/dao/init.lua | 6 +++++- kong/db/init.lua | 4 ---- kong/db/strategies/connector.lua | 4 +--- kong/db/strategies/init.lua | 6 ++++++ .../kong/plugins/dbless-pagination-test/handler.lua | 7 +------ 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/kong/db/dao/init.lua b/kong/db/dao/init.lua index b064bf126124..ddc432c7255b 100644 --- a/kong/db/dao/init.lua +++ b/kong/db/dao/init.lua @@ -966,12 +966,16 @@ function _M.new(db, schema, strategy, errors) local fk_methods = generate_foreign_key_methods(schema) local super = setmetatable(fk_methods, DAO) + local pagination = strategy.connector and + strategy.connector.defaults.pagination or + defaults.pagination + local self = { db = db, schema = schema, strategy = strategy, errors = errors, - pagination = kong_table.shallow_copy(defaults.pagination), + pagination = kong_table.shallow_copy(pagination), super = super, } diff --git a/kong/db/init.lua b/kong/db/init.lua index a2d87a709b1e..e670779ab0a7 100644 --- a/kong/db/init.lua +++ b/kong/db/init.lua @@ -118,10 +118,6 @@ function DB.new(kong_config, strategy) return nil, fmt("no strategy found for schema '%s'", schema.name) end daos[schema.name] = DAO.new(self, schema, strategy, errors) - - -- check pagination.max_page_size - assert(daos[schema.name].pagination.max_page_size == - strategy == "off" and 2048 or 50000) end end diff --git a/kong/db/strategies/connector.lua b/kong/db/strategies/connector.lua index d1b603f9c2df..bfc2d530061c 100644 --- a/kong/db/strategies/connector.lua +++ b/kong/db/strategies/connector.lua @@ -7,9 +7,7 @@ local Connector = { pagination = { page_size = 1000, -- lmdb will not support huge page size - max_page_size = kong and kong.configuration and - kong.configuration.database == "off" and - 2048 or 50000, + max_page_size = 50000, }, }, } diff --git a/kong/db/strategies/init.lua b/kong/db/strategies/init.lua index 90f7968a1ec7..99a5588d07d8 100644 --- a/kong/db/strategies/init.lua +++ b/kong/db/strategies/init.lua @@ -33,6 +33,12 @@ function _M.new(kong_config, database, schemas, errors) do local base_connector = require "kong.db.strategies.connector" + + -- lmdb will not support huge page size + if database == "off" then + base_connector.defaults.pagination.max_page_size = 2048 + end + local mt = getmetatable(connector) setmetatable(mt, { __index = function(t, k) diff --git a/spec/fixtures/custom_plugins/kong/plugins/dbless-pagination-test/handler.lua b/spec/fixtures/custom_plugins/kong/plugins/dbless-pagination-test/handler.lua index 5275e1962094..ef6f25cc3fde 100644 --- a/spec/fixtures/custom_plugins/kong/plugins/dbless-pagination-test/handler.lua +++ b/spec/fixtures/custom_plugins/kong/plugins/dbless-pagination-test/handler.lua @@ -7,15 +7,10 @@ local LmdbPaginationTestHandler = { } -local log = ngx.log -local ERR = ngx.ERR - - local function test() local db = kong.db - --assert(db.routes.pagination.max_page_size == 2048) - ngx.log(ngx.DEBUG, "xxx LmdbPaginationTestHandler ", db.routes.pagination.max_page_size) + assert(db.routes.pagination.max_page_size == 2048) end