[Tags performance] Improve event view

This commit is contained in:
danielmaya 2018-09-27 18:11:13 +02:00
parent 453fb3f67b
commit aceb67dd69
2 changed files with 71 additions and 115 deletions

View File

@ -722,7 +722,8 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
$condition = '';
$group_conditions = array();
$without_tags = array();
$has_secondary = enterprise_hook('agents_is_using_secondary_groups');
// The acltags array contains the groups with the acl propagation applied
// after the changes done into the 'tags_get_user_groups_and_tags' function.
@ -736,13 +737,21 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
$agent_condition = sprintf('((tagente.id_grupo = %d %s)',$group_id,$tag_join);
}
$group_conditions[] = $agent_condition;
} else {
$without_tags[] = $group_id;
}
}
if (!empty($group_conditions)) {
$condition = implode(' OR ', $group_conditions);
}
if (!empty($without_tags)) {
if (!empty($condition)) {
$condition .= ' OR ';
}
$in_group = implode(",",$without_tags);
$condition .= sprintf('(tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))',$in_group,$in_group);
}
$condition = !empty($condition) ? "($condition)" : '';
return $condition;
@ -824,102 +833,50 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group
// Get all tags of the system
$all_tags = tags_get_all_tags(false);
// Juanma (08/05/2014) Fix : Will have all groups retrieved (also propagated ones)
$_groups_not_in = '';
$without_tags = array();
foreach ($acltags as $group_id => $group_tags) {
// Group condition (The module belongs to an agent of the group X)
$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
//$_groups_not_in .= implode(',', array_values(groups_get_id_recursive($group_id))) . ',';
// Tags condition (The module has at least one of the restricted tags)
$tags_condition = '';
// NO check if there is not tag associated with groups
if (empty($group_tags)) {
// FIXME: Not properly way to increse performance
if(enterprise_hook('agents_is_using_secondary_groups')){
$tags_condition = "id_grupo = ".$group_id . " OR id_group = " . $group_id;
}
else{
$tags_condition = "id_grupo = ".$group_id;
}
}
else {
if (!is_array($group_tags)) {
$group_tags = explode(',', $group_tags);
}
foreach ($group_tags as $tag) {
// If the tag ID doesnt exist, ignore
if (!isset($all_tags[$tag])) {
continue;
}
if ($tags_condition != '') {
$tags_condition .= " OR \n";
}
//~ // Add as condition all the posibilities of the serialized tags
//~ $tags_condition .= sprintf('tags LIKE "%s,%%"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s,%%"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%s %%"',io_safe_input($all_tags[$tag]));
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s %%"',io_safe_input($all_tags[$tag]));
if ($force_group_and_tag) {
if (!empty($all_tags[$tag])) {
if ($force_equal) {
$tags_condition .= sprintf('(tags = "%s"',io_safe_input($all_tags[$tag]));
} else {
$tags_condition .= "(tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
}
$childrens = groups_get_childrens($group_id, null, true);
if (empty($childrens)) {
$tags_condition .= sprintf(' AND id_grupo = %d )', $group_id);
} else {
$childrens_ids[] = $group_id;
foreach ($childrens as $child) {
$childrens_ids[] = (int)$child['id_grupo'];
}
$ids_str = implode(',', $childrens_ids);
$tags_condition .= sprintf(' AND id_grupo IN (%s) )', $ids_str);
}
} else {
$tags_condition .= "id_grupo = ".$group_id;
}
} else {
if ($force_equal) {
$tags_condition .= sprintf('tags = "%s"',io_safe_input($all_tags[$tag]));
} else {
$tags_condition .= "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
}
}
}
}
// If there is not tag condition ignore
if (empty($tags_condition)) {
$without_tags []= $group_id;
continue;
}
if ($condition != '') {
$condition .= ' OR ';
// Group condition (The module belongs to an agent of the group X)
//$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
$group_condition = "(id_grupo = $group_id OR id_group = $group_id)";
// Tags condition (The module has at least one of the restricted tags)
$tags_condition = '';
$tags_condition_array = array();
foreach ($group_tags as $tag) {
// If the tag ID doesnt exist, ignore
if (!isset($all_tags[$tag])) continue;
$tags_condition_array[] = $force_equal
? sprintf('tags = "%s"',io_safe_input($all_tags[$tag]))
: "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
}
$condition .= "($tags_condition)\n";
// If there is not tag currently in Pandora, block the group info
if (empty($tags_condition_array)) {
$tags_condition_array[] = "1=0";
}
$tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")";
$condition[] = "($tags_condition)\n";
}
//Commented because ACLs propagation don't work
/*
if (!empty($condition)) {
// Juanma (08/05/2014) Fix : Also add events of other groups (taking care of propagate ACLs func!)
if (!empty($_groups_not_in))
$condition = sprintf("\n((%s) OR id_grupo NOT IN (%s))", $condition, rtrim($_groups_not_in, ','));
if (empty($condition)) {
return " 1=1 ";
}
$condition = implode(' OR ', $condition);
if (!empty($without_tags)) {
$condition .= ' OR ';
$in_group = implode(",",$without_tags);
$condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group);
}
*/
return $condition;
}
@ -2413,7 +2370,7 @@ function tags_get_user_groups_and_tags ($id_user = false, $access = 'AR', $stric
$return = array();
foreach ($acls as $acl) {
$return[$acl["id_grupo"]] = $acl["tags"][get_acl_column($access)];
$return[$acl["id_grupo"]] = implode(",",$acl["tags"][get_acl_column($access)]);
}
return $return;

View File

@ -207,22 +207,9 @@ function groups_combine_acl($acl_group_a, $acl_group_b){
"vconsole_management" => 1,
"tags" => 1,
);
if ($acl_group_a['tags']) users_get_explode_tags($acl_group_a);
if ($acl_group_b['tags']) users_get_explode_tags($acl_group_b);
if (is_array($acl_group_a['tags']) && is_array($acl_group_b['tags'])) {
foreach ($acl_group_a['tags'] as $key => $value) {
$acl_group_b['tags'][$key] = implode(
',',
array_merge(
$value,
$acl_group_b['tags'][$key]
)
);
}
} else if (is_array($acl_group_a['tags'])) {
$acl_group_b['tags'] = $acl_group_a['tags'];
foreach ($acl_group_a['tags'] as $key => $value) {
$acl_group_b['tags'][$key] = array_merge($value, $acl_group_b['tags'][$key]);
}
foreach ($acl_list as $acl => $aux) {
@ -289,6 +276,8 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
foreach ($raw_forest as $g) {
// XXX, following code must be remade (TAG)
users_get_explode_tags($g);
if (!isset($forest_acl[$g["id_grupo"]] )) {
$forest_acl[$g["id_grupo"]] = $g;
}
@ -1073,16 +1062,26 @@ function users_get_strict_mode_groups($id_user, $return_group_all) {
}
function users_get_explode_tags(&$group) {
if (is_array($group['tags'])) return;
$aux = explode(',', $group['tags']);
$group['tags'] = array();
$group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array();
$group['tags']['agent_edit'] = ($group['agent_edit']) ? $aux : array();
$group['tags']['agent_disable'] = ($group['agent_disable']) ? $aux : array();
$group['tags']['event_view'] = ($group['event_view']) ? $aux : array();
$group['tags']['event_edit'] = ($group['event_edit']) ? $aux : array();
$group['tags']['event_management'] = ($group['event_management']) ? $aux : array();
if (empty($group['tags'])) {
$group['tags'] = array();
$group['tags']['agent_view'] = array();
$group['tags']['agent_edit'] = array();
$group['tags']['agent_disable'] = array();
$group['tags']['event_view'] = array();
$group['tags']['event_edit'] = array();
$group['tags']['event_management'] = array();
} else {
$aux = explode(',', $group['tags']);
$group['tags'] = array();
$group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array();
$group['tags']['agent_edit'] = ($group['agent_edit']) ? $aux : array();
$group['tags']['agent_disable'] = ($group['agent_disable']) ? $aux : array();
$group['tags']['event_view'] = ($group['event_view']) ? $aux : array();
$group['tags']['event_edit'] = ($group['event_edit']) ? $aux : array();
$group['tags']['event_management'] = ($group['event_management']) ? $aux : array();
}
}
?>