fixed performance problems

This commit is contained in:
alejandro.campos@artica.es 2022-11-03 18:20:39 +01:00
parent 08ab924160
commit 514b350e14
2 changed files with 167 additions and 20 deletions

View File

@ -1815,9 +1815,9 @@ $class = 'databox filters';
$all_agents = agents_get_agents_selected($group); $all_agents = agents_get_agents_selected($group);
html_print_select( html_print_select(
$all_agents, [],
'id_agents2[]', 'id_agents2[]',
$id_agents, '',
$script = '', $script = '',
'', '',
0, 0,
@ -6074,6 +6074,79 @@ function addGeneralRow() {
} }
} }
function loadGeneralAgents(agent_group) {
var params = [];
var group = <?php echo $group; ?>;
group = agent_group || group;
params.push("get_agents=1");
params.push("group="+parseInt(group));
params.push('id_agents=<?php echo json_encode($id_agents); ?>');
params.push("page=include/ajax/reporting.ajax");
$('#id_agents2')
.find('option')
.remove();
$('#id_agents2')
.append('<option>Loading agents...</option>');
jQuery.ajax ({
data: params.join ("&"),
type: 'POST',
url: action=
<?php
echo '"'.ui_get_full_url(
false,
false,
false,
false
).'"';
?>
+ "/ajax.php",
timeout: 300000,
dataType: 'json',
success: function (data) {
if (data['correct']) {
$('#id_agents2')
.find('option')
.remove();
var selectElements = [];
var selectedStr = 'selected="selected"';
if (data['select_agents'] === null) {
return;
}
if (Array.isArray(data['select_agents'])) {
data['select_agents'].forEach(function(agentAlias, agentID) {
var optionAttr = '';
if (typeof data['agents_selected'][agentID] !== 'undefined') {
optionAttr = ' selected="selected"';
}
$('#id_agents2')
.append('<option value="'+agentID+'" '+optionAttr+'>'+agentAlias+'</option>');
});
} else {
for (const [agentID, agentAlias] of Object.entries(data['select_agents'])) {
var optionAttr = '';
if (typeof data['agents_selected'][agentID] !== 'undefined') {
optionAttr = ' selected="selected"';
}
$('#id_agents2')
.append('<option value="'+agentID+'" '+optionAttr+'>'+agentAlias+'</option>');
}
}
}
}
});
}
function loadLogAgents() { function loadLogAgents() {
var params = []; var params = [];
@ -6111,16 +6184,33 @@ function loadLogAgents() {
.remove(); .remove();
var selectElements = []; var selectElements = [];
var selectedStr = 'selected="selected"' var selectedStr = 'selected="selected"';
data['select_agents'].forEach(function(agentAlias, agentID) {
var optionAttr = '';
if (typeof data['agents_selected'][agentID] !== 'undefined') {
optionAttr = ' selected="selected"';
}
$('#id_agents3') if (data['select_agents'] === null) {
.append('<option value="'+agentID+'" '+optionAttr+'>'+agentAlias+'</option>'); return;
}); }
if (Array.isArray(data['select_agents'])) {
data['select_agents'].forEach(function(agentAlias, agentID) {
var optionAttr = '';
if (typeof data['agents_selected'][agentID] !== 'undefined') {
optionAttr = ' selected="selected"';
}
$('#id_agents3')
.append('<option value="'+agentID+'" '+optionAttr+'>'+agentAlias+'</option>');
});
} else {
for (const [agentID, agentAlias] of Object.entries(data['select_agents'])) {
var optionAttr = '';
if (typeof data['agents_selected'][agentID] !== 'undefined') {
optionAttr = ' selected="selected"';
}
$('#id_agents3')
.append('<option value="'+agentID+'" '+optionAttr+'>'+agentAlias+'</option>');
}
}
} }
} }
}); });
@ -6587,6 +6677,13 @@ function chooseType() {
$("#lapse_select").val('0').trigger('change'); $("#lapse_select").val('0').trigger('change');
$("#hidden-lapse").val('0'); $("#hidden-lapse").val('0');
} }
loadGeneralAgents();
$("#combo_group").change(function() {
loadGeneralAgents($(this).val());
});
break; break;
case 'event_report_group': case 'event_report_group':
@ -6782,6 +6879,12 @@ function chooseType() {
$("#agents_modules_row").show(); $("#agents_modules_row").show();
$("#modules_row").show(); $("#modules_row").show();
$("#row_historical_db_check").hide(); $("#row_historical_db_check").hide();
loadGeneralAgents();
$("#combo_group").change(function() {
loadGeneralAgents($(this).val());
});
break; break;
case 'inventory_changes': case 'inventory_changes':
@ -7158,7 +7261,6 @@ function change_custom_fields_macros_report(id) {
"macro_id": id "macro_id": id
}, },
function (data, status) { function (data, status) {
console.log(id);
$("td#table-macros-definition-"+id+"-value").empty(); $("td#table-macros-definition-"+id+"-value").empty();
$("td#table-macros-definition-"+id+"-value").append(data); $("td#table-macros-definition-"+id+"-value").append(data);
}, },

View File

@ -26,8 +26,10 @@ if (! check_acl($config['id_user'], 0, 'RW')) {
} }
$get_log_agents = (bool) get_parameter('get_log_agents', 0); $get_log_agents = (bool) get_parameter('get_log_agents', 0);
$get_agents = (bool) get_parameter('get_agents', 0);
$agents_id = get_parameter('id_agents', []); $agents_id = get_parameter('id_agents', []);
$agents_id = get_parameter('source', 0); $source = get_parameter('source', 0);
$group = get_parameter('group', 0);
$delete_sla_item = get_parameter('delete_sla_item', 0); $delete_sla_item = get_parameter('delete_sla_item', 0);
$delete_general_item = get_parameter('delete_general_item', 0); $delete_general_item = get_parameter('delete_general_item', 0);
$get_custom_sql = get_parameter('get_custom_sql', 0); $get_custom_sql = get_parameter('get_custom_sql', 0);
@ -248,7 +250,55 @@ if ($change_custom_fields_macros_report === true) {
return; return;
} }
if ($get_agents === true) {
$agents_id = str_replace('&quot;', '', $agents_id);
try {
$agents_id = json_decode($agents_id, true);
} catch (Exception $e) {
$data['correct'] = 0;
echo json_encode($data);
return;
}
$agents = agents_get_agents_selected($group);
if (isset($agents) && is_array($agents)) {
foreach ($agents as $key => $value) {
$select_agents[$key] = $value;
}
}
if ((empty($select_agents)) || $select_agents == -1) {
$agents = [];
}
$agents_selected = [];
if (is_array($agents_id) === true || is_object($agents_id) === true) {
foreach ($select_agents as $key => $a) {
if (in_array((string) $key, $agents_id) === true) {
$agents_selected[$key] = $key;
}
}
}
$data['select_agents'] = $select_agents;
$data['agents_selected'] = $agents_selected;
$data['correct'] = 1;
if ($result === false) {
$data['correct'] = 0;
}
echo json_encode($data);
return;
}
if ($get_log_agents === true) { if ($get_log_agents === true) {
$agents_id = str_replace('&quot;', '', $agents_id);
try { try {
$agents_id = json_decode($agents_id, true); $agents_id = json_decode($agents_id, true);
} catch (Exception $e) { } catch (Exception $e) {
@ -259,15 +309,10 @@ if ($get_log_agents === true) {
if ($source) { if ($source) {
$sql_log_report = 'SELECT id_agente, alias $sql_log_report = 'SELECT id_agente, alias
FROM tagente, tagent_module_log FROM tagente';
WHERE tagente.id_agente = tagent_module_log.id_agent
AND tagente.disabled = 0
AND tagent_module_log.source like "'.$source.'"';
} else { } else {
$sql_log_report = 'SELECT id_agente, alias $sql_log_report = 'SELECT id_agente, alias
FROM tagente, tagent_module_log FROM tagente';
WHERE tagente.id_agente = tagent_module_log.id_agent
AND tagente.disabled = 0';
} }
$all_agent_log = db_get_all_rows_sql($sql_log_report); $all_agent_log = db_get_all_rows_sql($sql_log_report);