massive operations over events

This commit is contained in:
fbsanchez 2019-06-18 14:26:55 +02:00
parent 823581f398
commit 22272225b8
4 changed files with 103 additions and 33 deletions

View File

@ -109,7 +109,7 @@ if ($in_process_event) {
$id_evento = get_parameter('id_evento', 0); $id_evento = get_parameter('id_evento', 0);
// Check acl. // Check acl.
echo events_update_status($id_evento, EVENT_PROCESS, $filter); var_dump(events_update_status($id_evento, EVENT_PROCESS, $filter));
return; return;
} }

View File

@ -243,8 +243,9 @@ function events_delete($id_evento, $filter=null, $history=false)
true true
); );
$delete_sql = sprintf( $target_ids = db_get_all_rows_sql(
'DELETE tu FROM %s tu INNER JOIN ( %s ) tf sprintf(
'SELECT tu.id_evento FROM %s tu INNER JOIN ( %s ) tf
ON tu.estado = tf.estado ON tu.estado = tf.estado
AND tu.evento = tf.evento AND tu.evento = tf.evento
AND tu.id_agente = tf.id_agente AND tu.id_agente = tf.id_agente
@ -253,7 +254,25 @@ function events_delete($id_evento, $filter=null, $history=false)
$table, $table,
$sql, $sql,
$id_evento $id_evento
)
); );
// Try to avoid deadlock while updating full set.
if ($target_ids !== false && count($target_ids) > 0) {
$target_ids = array_reduce(
$target_ids,
function ($carry, $item) {
$carry[] = $item['id_evento'];
return $carry;
}
);
$delete_sql = sprintf(
'DELETE FROM %s WHERE id_evento IN (%s)',
$table,
join(', ', $target_ids)
);
}
break; break;
} }
@ -366,10 +385,12 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
global $config; global $config;
if (!$status) { if (!$status) {
error_log('No hay estado');
return false; return false;
} }
if (!isset($id_evento) || $id_evento <= 0) { if (!isset($id_evento) || $id_evento <= 0) {
error_log('No hay id_evento');
return false; return false;
} }
@ -413,23 +434,43 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
true true
); );
$update_sql = sprintf( $target_ids = db_get_all_rows_sql(
'UPDATE %s tu INNER JOIN ( %s ) tf sprintf(
'SELECT tu.id_evento FROM %s tu INNER JOIN ( %s ) tf
ON tu.estado = tf.estado ON tu.estado = tf.estado
AND tu.evento = tf.evento AND tu.evento = tf.evento
AND tu.id_agente = tf.id_agente AND tu.id_agente = tf.id_agente
AND tu.id_agentmodule = tf.id_agentmodule AND tu.id_agentmodule = tf.id_agentmodule
AND tf.max_id_evento = %d AND tf.max_id_evento = %d',
SET tu.estado = %d,
tu.ack_utimestamp = %d,
tu.id_usuario = "%s"',
$table, $table,
$sql, $sql,
$id_evento, $id_evento
)
);
// Try to avoid deadlock while updating full set.
if ($target_ids !== false && count($target_ids) > 0) {
$target_ids = array_reduce(
$target_ids,
function ($carry, $item) {
$carry[] = $item['id_evento'];
return $carry;
}
);
$update_sql = sprintf(
'UPDATE %s
SET estado = %d,
ack_utimestamp = %d,
id_usuario = "%s"
WHERE id_evento IN (%s)',
$table,
$status, $status,
time(), time(),
$config['id_user'] $config['id_user'],
join(',', $target_ids)
); );
}
break; break;
} }

View File

@ -710,6 +710,9 @@ function update_event(table, id_evento, type, row) {
.remove(); .remove();
} }
} }
},
error: function() {
processed += 1;
} }
}); });
} }
@ -804,17 +807,30 @@ function execute_event_response(event_list_btn) {
switch (response_id) { switch (response_id) {
case "in_progress_selected": case "in_progress_selected":
$(".chk_val:checked").each(function() { $(".chk_val:checked").each(function() {
in_process_event(dt_events, $(this).val(), this.parentElement); // Parent: TD. GrandParent: TR.
in_process_event(
dt_events,
$(this).val(),
this.parentElement.parentElement
);
}); });
break; break;
case "validate_selected": case "validate_selected":
$(".chk_val:checked").each(function() { $(".chk_val:checked").each(function() {
validate_event(dt_events, $(this).val(), this.parentElement); validate_event(
dt_events,
$(this).val(),
this.parentElement.parentElement
);
}); });
break; break;
case "delete_selected": case "delete_selected":
$(".chk_val:checked").each(function() { $(".chk_val:checked").each(function() {
delete_event(dt_events, $(this).val(), this.parentElement); delete_event(
dt_events,
$(this).val(),
this.parentElement.parentElement
);
}); });
break; break;
} }

View File

@ -85,9 +85,9 @@ table.dataTable tbody td {
.info_table.events tr > th { .info_table.events tr > th {
padding-left: 1em; padding-left: 1em;
font-size: 1.3em; font-size: 8pt;
font-weight: 400; font-weight: 300;
border-bottom: 2px solid #878787; border-bottom: 1px solid #878787;
cursor: pointer; cursor: pointer;
} }
@ -315,3 +315,16 @@ div.multi-response-buttons {
width: 100%; width: 100%;
text-align: right; text-align: right;
} }
div.criticity {
width: 150px;
height: 2em;
color: #fff;
text-align: center;
border-radius: 5px;
font-size: 0.8em;
padding: 5px;
margin: 0;
display: table-cell;
vertical-align: middle;
}