perf: used empty table if the user is not enabled any plugin. (#1967)

This commit is contained in:
YuanSheng Wang 2020-08-04 09:30:13 +08:00 committed by GitHub
parent 4cbb324cca
commit 2073087909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -38,4 +38,5 @@ return {
etcd = require("apisix.core.etcd"),
http = require("apisix.core.http"),
tablepool= require("tablepool"),
empty_tab= {},
}

View File

@ -451,8 +451,8 @@ function _M.http_access_phase()
api_ctx.var.upstream_connection = api_ctx.var.http_connection
end
local plugins = core.tablepool.fetch("plugins", 32, 0)
api_ctx.plugins = plugin.filter(route, plugins)
local plugins = plugin.filter(route)
api_ctx.plugins = plugins
run_plugin("rewrite", plugins, api_ctx)
if api_ctx.consumer then
@ -631,7 +631,7 @@ function _M.http_log_phase()
end
core.ctx.release_vars(api_ctx)
if api_ctx.plugins then
if api_ctx.plugins and api_ctx.plugins ~= core.empty_tab then
core.tablepool.release("plugins", api_ctx.plugins)
end

View File

@ -229,16 +229,16 @@ end
function _M.filter(user_route, plugins)
plugins = plugins or core.table.new(#local_plugins * 2, 0)
local user_plugin_conf = user_route.value.plugins
if user_plugin_conf == nil or
core.table.nkeys(user_plugin_conf) == 0 then
if local_conf and local_conf.apisix.enable_debug then
core.response.set_header("Apisix-Plugins", "no plugin")
end
return plugins
return core.empty_tab
end
plugins = plugins or core.tablepool.fetch("plugins", 32, 0)
for _, plugin_obj in ipairs(local_plugins) do
local name = plugin_obj.name
local plugin_conf = user_plugin_conf[name]