[Tags performance] fermin revision 1

This commit is contained in:
fermin831 2018-10-03 11:13:25 +02:00
parent 942c5391f9
commit 7ffeaaf50b
8 changed files with 54 additions and 219 deletions

View File

@ -174,7 +174,6 @@ function mainInsertData() {
$table->data[1][0] = __('Module');
$modules = array ();
if ($agent_id){
// TODO TAGS agents_get_modules
$modules = agents_get_modules ($agent_id, false, array("delete_pending" => 0));
}
$table->data[1][1] = html_print_select ($modules, 'id_agent_module', $id_agent_module, true,

View File

@ -612,7 +612,7 @@ echo "<tr><th style='background-color:#b1b1b1;font-weight:bold;font-style:italic
$server_name = db_get_value_sql("SELECT name FROM tserver WHERE master = 1");
$agent_id= db_get_value_sql ("SELECT id_agente FROM tagente WHERE nombre = '$server_name'");
// TODO TAGS agents_get_modules
$id_modules = agents_get_modules($agent_id);
$id_modules = array (

View File

@ -423,9 +423,11 @@ foreach ($order as $ord) {
$limit = (int) $config["block_size"];
$offset = (int) get_parameter ('offset');
$params = implode(',',
$params = ($checked)
? "tagente_modulo.*, tmodule_group.*"
: implode(',',
array(
'id_agente_modulo',
'tagente_modulo.id_agente_modulo',
'id_tipo_modulo',
'descripcion',
'nombre',
@ -451,81 +453,49 @@ $where = sprintf("delete_pending = 0 AND id_agente = %s", $id_agente);
$search_string_entities = io_safe_input($search_string);
$basic_where = sprintf("(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, $search_string_entities);
// TODO revision tag
$where_tags = tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 'tagente_modulo');
// Tags acl
$tags_join = "";
$tags_condition = "";
$agent_tags = tags_get_user_applied_agent_tags($id_agente);
if ($agent_tags !== true) {
$where_tags = " AND ttag_module.id_tag IN (" . implode(',', $agent_tags) . ")";
}
$paginate_module = false;
if (isset($config['paginate_module']))
$paginate_module = $config['paginate_module'];
switch ($config["dbtype"]) {
case "postgresql":
if ($paginate_module) {
$limit_sql = " LIMIT $limit OFFSET $offset ";
}
else {
$limit_sql = '';
}
case "mysql":
if ($paginate_module) {
if (!isset($limit_sql)) {
$limit_sql = " LIMIT $offset, $limit ";
}
}
else {
$limit_sql = '';
}
if ($checked) {
$sql = sprintf("SELECT *
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE %s %s %s %s %s",
$basic_where, $where, $where_tags, $order_sql, $limit_sql);
}
else {
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE %s %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql, $limit_sql);
}
$modules = db_get_all_rows_sql($sql);
break;
case "oracle":
$set = array();
if ($paginate_module) {
$set['limit'] = $limit;
$set['offset'] = $offset;
}
if ($checked) {
$sql = sprintf("SELECT *
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE %s %s %s %s",
$basic_where, $where, $where_tags, $order_sql);
}
else {
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql);
}
$modules = oracle_recode_query ($sql, $set, 'AND', false);
break;
if ($paginate_module) {
if (!isset($limit_sql)) {
$limit_sql = " LIMIT $offset, $limit ";
}
}
else {
$limit_sql = '';
}
$sql = sprintf("SELECT tagente_modulo.*, tmodule_group.*
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
LEFT JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo
WHERE %s %s %s
GROUP BY tagente_modulo.id_agente_modulo
%s %s",
$basic_where, $where, $where_tags,
$order_sql, $limit_sql
);
$sql_total_modules = sprintf("SELECT count(*)
$modules = db_get_all_rows_sql($sql);
$sql_total_modules = sprintf(
"SELECT count(DISTINCT(tagente_modulo.id_agente_modulo))
FROM tagente_modulo
WHERE %s %s %s", $basic_where, $where, $where_tags);
LEFT JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo
WHERE %s %s %s", $basic_where, $where, $where_tags
);
$total_modules = db_get_value_sql($sql_total_modules);

View File

@ -70,7 +70,7 @@ if (! $id_agente) {
$table->data[0][0] = __('Module');
$modules = array ();
// TODO TAGS agents_get_modules
if ($id_agente)
$modules = agents_get_modules ($id_agente, false, array("delete_pending" => 0));

View File

@ -76,147 +76,14 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all'
if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1))
$filter_for_module_deletion = false;
else
$filter_for_module_deletion = sprintf('nombre IN ("%s")', implode('","', $module_name));
$filter_for_module_deletion = sprintf('tagente_modulo.nombre IN ("%s")', implode('","', $module_name));
if ($config['dbtype'] == "oracle") {
$all_agent_modules = false;
if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1)) {
$all_agent_modules = true;
}
$names_to_long = array();
$i = 0;
foreach ($module_name as $name) {
if (strlen($name) > 30) {
$original_names[] = $module_name[$i];
unset($module_name[$i]);
$names_to_long[] = substr($name, 0, 28) . "%";
}
$i++;
}
$modules = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$modules .= sprintf(" id_agente IN (%s)", implode(",", $id_agents));
if (!empty($module_name) && (!$all_agent_modules)) {
$modules .= sprintf(" AND nombre IN ('%s')", implode("','", $module_name));
}
$modules = db_get_all_rows_sql($modules);
$modules2 = "";
if (!empty($names_to_long) && (!$all_agent_modules)) {
$modules2 = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$modules2 .= sprintf(" id_agente IN (%s) AND (", implode(",", $id_agents));
$j = 0;
foreach ($names_to_long as $name) {
if ($j == 0) {
$modules2 .= "nombre LIKE ('" . $name . "')";
}
else {
$modules2 .= " OR nombre LIKE ('" . $name . "')";
}
$j++;
}
$modules2 .= ")";
$modules2 = db_get_all_rows_sql($modules2);
$modules = array_merge($modules, $modules2);
}
$all_names = array();
foreach ($modules as $module) {
$all_modules[] = $module['id_agente_modulo'];
$all_names[] = $module['nombre'];
}
$modules = $all_modules;
$modules = array_unique($modules);
if (!empty($names_to_long) && (!$all_agent_modules)) {
$j = 0;
foreach ($all_names as $name) {
if (strlen($name) > 30) {
if (!in_array($name, $original_names)) {
unset($modules[$j]);
}
}
$j++;
}
}
}
else {
// TODO TAGS agents_get_modules
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
$filter_for_module_deletion, true);
}
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
$filter_for_module_deletion, true);
}
else {
if ($config['dbtype'] == "oracle") {
$all_agent_modules = false;
$names_to_long = array();
if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1)) {
$all_agent_modules = true;
}
$i = 0;
foreach ($module_name as $name) {
if (strlen($name) > 30) {
$original_names[] = $module_name[$i];
unset($module_name[$i]);
$names_to_long[] = substr($name, 0, 28) . "%";
}
$i++;
}
$modules = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$any_agent = false;
if ($id_agents == null) {
$any_agent = true;
}
if (!empty($id_agents)) {
$modules .= sprintf(" id_agente IN (%s)", implode(",", $id_agents));
$agents_selected = true;
}
if (!empty($module_name) && (!$all_agent_modules)) {
if ($any_agent) {
$modules .= sprintf(" nombre IN ('%s')", implode("','", $module_name));
}
else {
$modules .= sprintf(" AND nombre IN ('%s')", implode("','", $module_name));
}
}
$modules = db_get_all_rows_sql($modules);
if (!empty($names_to_long) && (!$all_agent_modules)) {
$modules2 = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE";
$modules2 .= sprintf(" id_agente IN (%s) AND (", implode(",", $id_agents));
$j = 0;
foreach ($names_to_long as $name) {
if ($j == 0) {
$modules2 .= "nombre LIKE ('" . $name . "')";
}
else {
$modules2 .= " OR nombre LIKE ('" . $name . "')";
}
$j++;
}
$modules2 .= ")";
$modules2 = db_get_all_rows_sql($modules2);
$modules = array_merge($modules, $modules2);
}
$all_names = array();
foreach ($modules as $module) {
$all_modules[] = $module['id_agente_modulo'];
$all_names[] = $module['nombre'];
}
$modules = $all_modules;
$modules = array_unique($modules);
if (!empty($names_to_long) && (!$all_agent_modules)) {
$j = 0;
foreach ($all_names as $name) {
if (strlen($name) > 30) {
if (!in_array($name, $original_names)) {
unset($modules[$j]);
}
}
$j++;
}
}
}
else {
// TODO TAGS agents_get_modules
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
sprintf('nombre IN ("%s")', implode('","',$module_name)), true);
}
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
'tagente_modulo.nombre IN ("' . implode('","',$module_name) . '")', true);
}
if (($module_status == 'unknown') && ($module_name[0] == "0") && (is_array($module_name)) && (count($module_name) == 1)) {
@ -432,8 +299,6 @@ $table->data['form_modules_1'][3] = __('Select all modules of this type') . ' '
html_print_checkbox_extended("force_type", 'type', '', '', false,
'', 'style="margin-right: 40px;"', true);
$modules = array ();
if ($module_type != '') {
$filter = array ('id_tipo_modulo' => $module_type);
@ -441,9 +306,8 @@ if ($module_type != '') {
else {
$filter = false;
}
// TODO TAGS agents_get_modules
$names = agents_get_modules (array_keys ($agents),
'DISTINCT(nombre)', $filter, false);
'DISTINCT(tagente_modulo.nombre)', $filter, false);
foreach ($names as $name) {
$modules[$name['nombre']] = $name['nombre'];
}

View File

@ -1177,7 +1177,10 @@ function agents_get_modules ($id_agent = null, $details = false,
else {
$details = (array)$details;
$details = io_safe_input ($details);
$details = array_map(function ($a) { return 'tagente_modulo.' . $a;}, $details);
$details = array_map(function ($a) {
return preg_match('/tagente_modulo./i', $a) ? $a : 'tagente_modulo.' . $a;
},$details
);
}
$sql_tags_join = "";

View File

@ -2640,7 +2640,7 @@ function tags_get_module_policy_tags($id_tag, $id_module) {
* true if there is not any tag restriction
* array with all tags if there are tags configured
*/
function tags_get_user_applied_agent_tags ($id_agent, $access) {
function tags_get_user_applied_agent_tags ($id_agent, $access = "AR") {
global $config;
$agent_groups = agents_get_all_groups_agent($id_agent);

View File

@ -673,7 +673,7 @@ if (is_ajax ()) {
}
if ($status_modulo != -1) {
$filter['id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
$filter['tagente_modulo.id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions;
}
@ -685,7 +685,7 @@ if (is_ajax ()) {
if ($get_id_and_name)
$fields = array('id_agente_modulo', 'nombre');
if ($get_distinct_name)
$fields = array('DISTINCT(nombre)');
$fields = array('DISTINCT(tagente_modulo.nombre)');
$indexed = (bool) get_parameter ('indexed', true);
$agentName = (string) get_parameter ('agent_name', null);
@ -730,7 +730,6 @@ if (is_ajax ()) {
$id_agent = array_keys(
agents_get_group_agents(
array_keys(users_get_groups ()), $search, "none"));
// TODO TAGS agents_get_modules
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
}