[Tags performance] Fixed problems when there is not using secondary groups

This commit is contained in:
fermin831 2018-10-09 11:45:55 +02:00
parent 28f9e152e7
commit ec7c645d1b
1 changed files with 1 additions and 62 deletions

View File

@ -734,7 +734,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
if($has_secondary){
$agent_condition = sprintf('((tagente.id_grupo = %d OR tasg.id_group = %d) %s)',$group_id,$group_id,$tag_join);
} else {
$agent_condition = sprintf('((tagente.id_grupo = %d %s)',$group_id,$tag_join);
$agent_condition = sprintf('((tagente.id_grupo = %d %s))',$group_id,$tag_join);
}
$group_conditions[] = $agent_condition;
} else {
@ -757,67 +757,6 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
return $condition;
}
// The old function will be keeped to serve as reference of the changes done
/**
* Transform the acl_groups data into a SQL condition
*
* @param mixed acl_groups data calculated in tags_get_acl_tags function
*
* @return string SQL condition for tagente_module
*/
function tags_get_acl_tags_module_condition_old($acltags, $modules_table = '') {
if (!empty($modules_table))
$modules_table .= '.';
$condition = '';
$group_conditions = array();
// The acltags array contains the groups with the acl propagation applied
// after the changes done into the 'tags_get_user_groups_and_tags' function.
foreach ($acltags as $group_id => $group_tags) {
$tag_join = '';
if (!empty($group_tags)) {
$tag_join = sprintf('INNER JOIN ttag_module ttmc
ON tamc.id_agente_modulo = ttmc.id_agente_modulo
AND ttmc.id_tag IN (%s)',
is_array($group_tags) ? implode(',', $group_tags) : $group_tags);
}
// FIXME: Not properly way to increse performance
if(enterprise_hook('agents_is_using_secondary_groups')){
$agent_condition = sprintf('SELECT tamc.id_agente_modulo
FROM tagente_modulo tamc
%s
INNER JOIN tagente tac
ON tamc.id_agente = tac.id_agente
LEFT JOIN tagent_secondary_group tasg
ON tasg.id_agent = tac.id_agente
WHERE (tac.id_grupo = %d OR tasg.id_group = %d)',
$tag_join, $group_id, $group_id);
}
else{
$agent_condition = sprintf('SELECT tamc.id_agente_modulo
FROM tagente_modulo tamc
%s
INNER JOIN tagente tac
ON tamc.id_agente = tac.id_agente
AND tac.id_grupo = %d',
$tag_join, $group_id);
}
$sql_condition = sprintf('(%sid_agente_modulo IN (%s))', $modules_table, $agent_condition);
$group_conditions[] = $sql_condition;
$i++;
}
if (!empty($group_conditions))
$condition = implode(' OR ', $group_conditions);
$condition = !empty($condition) ? "($condition)" : '';
return $condition;
}
/**
* Transform the acl_groups data into a SQL condition
*