Time for a major improvement to LUA XML handler efficiency.
This commit is contained in:
parent
bdcf9bd41f
commit
dfba7f9405
|
|
@ -42,13 +42,6 @@
|
|||
dofile(scripts_dir.."/resources/functions/file_exists.lua");
|
||||
dofile(scripts_dir.."/resources/functions/explode.lua");
|
||||
|
||||
--connect to the database
|
||||
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
||||
dbh = database_handle('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--if the params class and methods do not exist then add them to prevent errors
|
||||
if (not params) then
|
||||
params = {}
|
||||
|
|
@ -103,21 +96,6 @@
|
|||
--prepare the api object
|
||||
api = freeswitch.API();
|
||||
|
||||
--get the domain_uuid
|
||||
if (domain_uuid == nil) then
|
||||
--get the domain_uuid
|
||||
if (domain_name ~= nil) then
|
||||
sql = "SELECT domain_uuid FROM v_domains ";
|
||||
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(rows)
|
||||
domain_uuid = rows["domain_uuid"];
|
||||
end);
|
||||
end
|
||||
end
|
||||
|
||||
--process the sections
|
||||
if (XML_REQUEST["section"] == "configuration") then
|
||||
configuration = scripts_dir.."/app/xml_handler/resources/scripts/configuration/"..XML_REQUEST["key_value"]..".lua";
|
||||
|
|
@ -134,6 +112,3 @@
|
|||
if (XML_REQUEST["section"] == "dialplan") then
|
||||
dofile(scripts_dir.."/app/xml_handler/resources/scripts/dialplan/dialplan.lua");
|
||||
end
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
|
@ -35,6 +35,28 @@
|
|||
--set the cache
|
||||
if (XML_STRING == "-ERR NOT FOUND") then
|
||||
|
||||
--connect to the database
|
||||
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
||||
dbh = database_handle('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--get the domain_uuid
|
||||
if (domain_uuid == nil) then
|
||||
--get the domain_uuid
|
||||
if (domain_name ~= nil) then
|
||||
sql = "SELECT domain_uuid FROM v_domains ";
|
||||
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(rows)
|
||||
domain_uuid = rows["domain_uuid"];
|
||||
end);
|
||||
end
|
||||
end
|
||||
|
||||
--get the variables
|
||||
vars = trim(api:execute("global_getvar", ""));
|
||||
|
||||
|
|
@ -234,6 +256,9 @@
|
|||
freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n");
|
||||
end
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
||||
--set the cache
|
||||
result = trim(api:execute("memcache", "set configuration:sofia.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' "..expire["sofia.conf"]));
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,29 @@
|
|||
|
||||
--set the cache
|
||||
if (XML_STRING == "-ERR NOT FOUND") then
|
||||
|
||||
--connect to the database
|
||||
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
||||
dbh = database_handle('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--get the domain_uuid
|
||||
if (domain_uuid == nil) then
|
||||
--get the domain_uuid
|
||||
if (domain_name ~= nil) then
|
||||
sql = "SELECT domain_uuid FROM v_domains ";
|
||||
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(rows)
|
||||
domain_uuid = rows["domain_uuid"];
|
||||
end);
|
||||
end
|
||||
end
|
||||
|
||||
--set the xml array and then concatenate the array to a string
|
||||
local xml = {}
|
||||
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]);
|
||||
|
|
@ -54,9 +77,6 @@
|
|||
sql = sql .. "where d.dialplan_context = '" .. call_context .. "' ";
|
||||
sql = sql .. "and d.dialplan_enabled = 'true' ";
|
||||
sql = sql .. "and d.dialplan_uuid = s.dialplan_uuid ";
|
||||
--if (call_context ~= "public") then
|
||||
-- sql = sql .. "and d.domain_uuid = '" .. domain_uuid .. "' ";
|
||||
--end
|
||||
sql = sql .. "order by ";
|
||||
sql = sql .. "d.dialplan_order asc, ";
|
||||
sql = sql .. "d.dialplan_name asc, ";
|
||||
|
|
@ -253,6 +273,9 @@
|
|||
if (debug["cache"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] dialplan:"..call_context.." source: database\n");
|
||||
end
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
else
|
||||
--replace the ' back to a single quote
|
||||
XML_STRING = XML_STRING:gsub("'", "'");
|
||||
|
|
|
|||
|
|
@ -24,6 +24,13 @@
|
|||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--connect to the database
|
||||
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
||||
dbh = database_handle('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--process when the sip profile is rescanned, sofia is reloaded, or sip redirect
|
||||
local xml = {}
|
||||
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]);
|
||||
|
|
@ -36,3 +43,6 @@
|
|||
table.insert(xml, [[ </section>]]);
|
||||
table.insert(xml, [[</document>]]);
|
||||
XML_STRING = table.concat(xml, "\n");
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
|
|
|||
|
|
@ -33,6 +33,28 @@
|
|||
|
||||
--set the cache
|
||||
if (XML_STRING == "-ERR NOT FOUND") then
|
||||
--connect to the database
|
||||
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
||||
dbh = database_handle('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--get the domain_uuid
|
||||
if (domain_uuid == nil) then
|
||||
--get the domain_uuid
|
||||
if (domain_name ~= nil) then
|
||||
sql = "SELECT domain_uuid FROM v_domains ";
|
||||
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(rows)
|
||||
domain_uuid = rows["domain_uuid"];
|
||||
end);
|
||||
end
|
||||
end
|
||||
|
||||
--build the call group array
|
||||
sql = [[
|
||||
select * from v_extensions
|
||||
|
|
@ -98,6 +120,9 @@
|
|||
table.insert(xml, [[</document>]]);
|
||||
XML_STRING = table.concat(xml, "\n");
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
||||
--set the cache
|
||||
result = trim(api:execute("memcache", "set directory:groups:"..domain_name.." '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,28 @@
|
|||
--group_call - call group has been called
|
||||
--user_call - user has been called
|
||||
|
||||
--connect to the database
|
||||
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
||||
dbh = database_handle('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--get the domain_uuid
|
||||
if (domain_uuid == nil) then
|
||||
--get the domain_uuid
|
||||
if (domain_name ~= nil) then
|
||||
sql = "SELECT domain_uuid FROM v_domains ";
|
||||
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(rows)
|
||||
domain_uuid = rows["domain_uuid"];
|
||||
end);
|
||||
end
|
||||
end
|
||||
|
||||
--get the extension information
|
||||
sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and (extension = '" .. user .. "' or number_alias = '" .. user .. "') and enabled = 'true' ";
|
||||
if (debug["sql"]) then
|
||||
|
|
@ -70,6 +92,9 @@
|
|||
table.insert(xml, [[</document>]]);
|
||||
XML_STRING = table.concat(xml, "\n");
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
||||
--send the xml to the console
|
||||
if (debug["xml_string"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: \n" .. XML_STRING .. "\n");
|
||||
|
|
|
|||
|
|
@ -66,20 +66,21 @@
|
|||
XML_STRING = trim(api:execute("memcache", "get directory:" .. user .. "@" .. domain_name));
|
||||
end
|
||||
if (XML_STRING == "-ERR NOT FOUND") then
|
||||
source = "database";
|
||||
continue = true;
|
||||
else
|
||||
source = "cache";
|
||||
continue = true;
|
||||
end
|
||||
else
|
||||
XML_STRING = "";
|
||||
source = "database";
|
||||
continue = true;
|
||||
end
|
||||
|
||||
--prevent processing for invalid user
|
||||
if (user == "*97") then
|
||||
continue = false;
|
||||
end
|
||||
|
||||
--prevent processing for invalid domains
|
||||
if (domain_uuid == nil) then
|
||||
source = "";
|
||||
continue = false;
|
||||
end
|
||||
|
||||
|
|
@ -97,8 +98,42 @@
|
|||
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is " .. dialed_extension .. "\n");
|
||||
end
|
||||
|
||||
--build the XML string from the database
|
||||
if (source == "database") then
|
||||
--database connection
|
||||
if (continue) then
|
||||
--connect to the database
|
||||
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
||||
dbh = database_handle('system');
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--get the domain_uuid
|
||||
if (domain_uuid == nil) then
|
||||
--get the domain_uuid
|
||||
if (domain_name ~= nil) then
|
||||
sql = "SELECT domain_uuid FROM v_domains ";
|
||||
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(rows)
|
||||
domain_uuid = rows["domain_uuid"];
|
||||
end);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--prevent processing for invalid domains
|
||||
if (domain_uuid == nil) then
|
||||
continue = false;
|
||||
end
|
||||
|
||||
--if load balancing is set to true then get the hostname
|
||||
if (continue) then
|
||||
if (load_balancing) then
|
||||
|
||||
--get the domain_name from domains
|
||||
if (domain_name == nil) then
|
||||
sql = "SELECT domain_name FROM v_domains ";
|
||||
|
|
@ -142,6 +177,7 @@
|
|||
--close the database connection
|
||||
dbh_switch:release();
|
||||
end
|
||||
end
|
||||
|
||||
--get the extension from the database
|
||||
if (continue) then
|
||||
|
|
@ -399,6 +435,9 @@
|
|||
table.insert(xml, [[</document>]]);
|
||||
XML_STRING = table.concat(xml, "\n");
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
||||
--set the cache
|
||||
if (user and domain_name) then
|
||||
result = trim(api:execute("memcache", "set directory:" .. user .. "@" .. domain_name .. " '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
|
||||
|
|
@ -415,7 +454,11 @@
|
|||
if (debug["cache"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] directory:" .. user .. "@" .. domain_name .. " source: database\n");
|
||||
end
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
--get the XML string from the cache
|
||||
if (source == "cache") then
|
||||
--replace the ' back to a single quote
|
||||
if (XML_STRING) then
|
||||
XML_STRING = XML_STRING:gsub("'", "'");
|
||||
|
|
|
|||
Loading…
Reference in New Issue