Improve performance.
This commit is contained in:
parent
1d4c7ec65c
commit
5b0f7d7d6e
2 changed files with 19 additions and 14 deletions
|
|
@ -3,16 +3,14 @@ local ngx = ngx
|
|||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local string_format = string.format
|
||||
local new_tab = require "table.new"
|
||||
local ngx_log = ngx.log
|
||||
local INFO = ngx.INFO
|
||||
local ERR = ngx.ERR
|
||||
local pcall = pcall
|
||||
|
||||
local _M = {}
|
||||
local MAX_NUMBER_OF_PLUGINS = 10000
|
||||
-- TODO: is this good for a dictionary?
|
||||
local plugins = new_tab(MAX_NUMBER_OF_PLUGINS, 0)
|
||||
local MAX_NUMBER_OF_PLUGINS = 20
|
||||
local plugins = {}
|
||||
|
||||
local function load_plugin(name)
|
||||
local path = string_format("plugins.%s.main", name)
|
||||
|
|
@ -27,8 +25,14 @@ local function load_plugin(name)
|
|||
end
|
||||
|
||||
function _M.init(names)
|
||||
local count = 0
|
||||
for _, name in ipairs(names) do
|
||||
if count >= MAX_NUMBER_OF_PLUGINS then
|
||||
ngx_log(ERR, "the total number of plugins exceed the maximum number: ", MAX_NUMBER_OF_PLUGINS)
|
||||
break
|
||||
end
|
||||
load_plugin(name)
|
||||
count = count + 1 -- ignore loading failure, just count the total
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue