Browse Source

Merge pull request #2108 from annando/1511-optimize-tables

Optimize tables on a daily base that are written very often
tags/3.4.3
Tobias Diekershoff 4 years ago
parent
commit
d3d0647ff8
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      include/cron.php

+ 21
- 0
include/cron.php View File

@@ -189,6 +189,27 @@ function cron_run(&$argv, &$argc){
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
}

// maximum table size in megabyte
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
if ($max_tablesize == 0)
$max_tablesize = 100 * 1000000; // Default are 100 MB

// Optimize some tables that need to be optimized
$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());
}


Loading…
Cancel
Save