Automatically optimize tables that are smaller than a definable size

pull/2108/head
Michael Vogel 2015-11-28 15:43:25 +01:00
rodzic a34dbf76a4
commit 3f66e0a9f6
1 zmienionych plików z 20 dodań i 7 usunięć

Wyświetl plik

@ -189,13 +189,26 @@ function cron_run(&$argv, &$argc){
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime); q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
} }
// Optimize some tables that are written often // maximum table size in megabyte
q("OPTIMIZE TABLE `cache`"); $max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
q("OPTIMIZE TABLE `session`"); if ($max_tablesize == 0)
q("OPTIMIZE TABLE `config`"); $max_tablesize = 100 * 1000000; // Default are 100 MB
q("OPTIMIZE TABLE `pconfig`");
q("OPTIMIZE TABLE `workerqueue`"); // Optimize some tables that need to be optimized
//q("OPTIMIZE TABLE `photo`"); // Could take too long $r = q("SHOW TABLE STATUS");
foreach($r as $table) {
// Don't optimize tables that needn't to be optimized
if ($table["Data_free"] == 0)
continue;
// Don't optimize tables that are too large
if ($table["Data_length"] > $max_tablesize)
continue;
// So optimize it
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
}
set_config('system','cache_last_cleared', time()); set_config('system','cache_last_cleared', time());
} }