Merge branch 'ent-2243-5204-rendimiento-exportacion-csv-log-viewer-3' into 'develop'

Added cache to agents_get_alias

See merge request artica/pandorafms!1949
This commit is contained in:
vgilc 2018-11-08 13:43:42 +01:00
commit 19fc5863d0

View File

@ -1314,7 +1314,7 @@ function agents_get_name ($id_agent, $case = "none") {
} }
/** /**
* Get alias of an agent. * Get alias of an agent (cached function).
* *
* @param int $id_agent Agent id. * @param int $id_agent Agent id.
* @param string $case Case (upper, lower, none) * @param string $case Case (upper, lower, none)
@ -1323,6 +1323,13 @@ function agents_get_name ($id_agent, $case = "none") {
*/ */
function agents_get_alias ($id_agent, $case = 'none') { function agents_get_alias ($id_agent, $case = 'none') {
global $config; global $config;
// Prepare cache
static $cache = array();
if (empty($case)) $case = 'none';
// Check cache
if (isset($cache[$case][$id_agent])) return $cache[$case][$id_agent];
if($config['dbconnection_cache'] == null && is_metaconsole()){ if($config['dbconnection_cache'] == null && is_metaconsole()){
$alias = (string) db_get_value ('alias', 'tmetaconsole_agent', 'id_tagente', (int) $id_agent); $alias = (string) db_get_value ('alias', 'tmetaconsole_agent', 'id_tagente', (int) $id_agent);
} else { } else {
@ -1331,13 +1338,15 @@ function agents_get_alias ($id_agent, $case = 'none') {
switch ($case) { switch ($case) {
case 'upper': case 'upper':
return mb_strtoupper($alias, 'UTF-8'); $alias = mb_strtoupper($alias, 'UTF-8');
break;
case 'lower': case 'lower':
return mb_strtolower($alias, 'UTF-8'); $alias = mb_strtolower($alias, 'UTF-8');
case 'none': break;
default:
return ($alias);
} }
$cache[$case][$id_agent] = $alias;
return $alias;
} }
function agents_get_alias_by_name ($name, $case = 'none') { function agents_get_alias_by_name ($name, $case = 'none') {