]> git.mxchange.org Git - friendica.git/commitdiff
Automatically optimize tables that are smaller than a definable size
authorMichael Vogel <icarus@dabo.de>
Sat, 28 Nov 2015 14:43:25 +0000 (15:43 +0100)
committerMichael Vogel <icarus@dabo.de>
Sat, 28 Nov 2015 14:43:25 +0000 (15:43 +0100)
include/cron.php

index 7927769de829b7dd06baca0638fa297ea2f70daf..d95d8bc601bfa7b19d7a5d89eaaa977c0c9e780a 100644 (file)
@@ -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);
                }
 
-               // Optimize some tables that are written often
-               q("OPTIMIZE TABLE `cache`");
-               q("OPTIMIZE TABLE `session`");
-               q("OPTIMIZE TABLE `config`");
-               q("OPTIMIZE TABLE `pconfig`");
-               q("OPTIMIZE TABLE `workerqueue`");
-               //q("OPTIMIZE TABLE `photo`"); // Could take too long
+               // 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());
        }