From 7a74f06037e655d56d68906b4fd855b943d8d739 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 28 Oct 2020 18:08:59 +0100 Subject: [PATCH] fixes #553 smartly remove the old history.summarized column Only when we have as few lines as possible in the history table, not before. --- admin/include/functions_history.inc.php | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/admin/include/functions_history.inc.php b/admin/include/functions_history.inc.php index 303e47c2b..43996c166 100644 --- a/admin/include/functions_history.inc.php +++ b/admin/include/functions_history.inc.php @@ -400,6 +400,7 @@ SELECT if ($count <= $conf['history_autopurge_keep_lines']) { + history_remove_summarized_column(); return; // no need to purge for now } @@ -463,6 +464,39 @@ DELETE WHERE id < '.$history_id_delete_before.' ;'; pwg_query($query); + + history_remove_summarized_column(); +} + +function history_remove_summarized_column() +{ + global $conf; + + if (isset($conf['history_summarized_dropped']) and $conf['history_summarized_dropped']) + { + return; + } + + $query = ' +SELECT + COUNT(*) + FROM '.HISTORY_TABLE.' +;'; + list($count) = pwg_db_fetch_row(pwg_query($query)); + + if ($count > $conf['history_autopurge_keep_lines']+$conf['history_autopurge_blocksize']) + { + // it's not yet time to remove history.summarized + return; + } + + $result = pwg_query('SHOW COLUMNS FROM `'.HISTORY_TABLE.'` LIKE "summarized";'); + if (pwg_db_num_rows($result)) + { + pwg_query('ALTER TABLE `'.HISTORY_TABLE.'` DROP COLUMN `summarized`;'); + } + + conf_update_param('history_summarized_dropped', true); } add_event_handler('get_history', 'get_history');