Skip to content
Snippets Groups Projects
Commit 268e26ea authored by Jared Hancock's avatar Jared Hancock
Browse files

Periodically optimize core tables

This is instead of optimizing the lock table for every cron run, which
wastes a lot of db server io
parent e3e8dfed
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,9 @@ class Cron {
function PurgeLogs() {
global $ost;
if($ost) $ost->purgeLogs();
// Once a day on a 5-minute cron
if (rand(1,300) == 42)
if($ost) $ost->purgeLogs();
}
function PurgeDrafts() {
......@@ -45,6 +47,47 @@ class Cron {
AttachmentFile::deleteOrphans();
}
function MaybeOptimizeTables() {
// Once a week on a 5-minute cron
$chance = rand(1,2000);
switch ($chance) {
case 42:
@db_query('OPTIMIZE TABLE '.TICKET_LOCK_TABLE);
break;
case 242:
@db_query('OPTIMIZE TABLE '.SYSLOG_TABLE);
break;
case 442:
@db_query('OPTIMIZE TABLE '.DRAFT_TABLE);
break;
// Start optimizing core ticket tables when we have an archiving
// system available
case 142:
#@db_query('OPTIMIZE TABLE '.TICKET_TABLE);
break;
case 542:
#@db_query('OPTIMIZE TABLE '.FORM_ENTRY_TABLE);
break;
case 642:
#@db_query('OPTIMIZE TABLE '.FORM_ANSWER_TABLE);
break;
case 342:
#@db_query('OPTIMIZE TABLE '.FILE_TABLE);
# XXX: Please do not add an OPTIMIZE for the file_chunk table!
break;
// Start optimizing user tables when we have a user directory
// sporting deletes
case 742:
#@db_query('OPTIMIZE TABLE '.USER_TABLE);
break;
case 842:
#@db_query('OPTIMIZE TABLE '.USER_EMAIL_TABLE);
break;
}
}
function run(){ //called by outside cron NOT autocron
global $ost;
if (!$ost || $ost->isUpgradePending())
......@@ -55,6 +98,7 @@ class Cron {
self::PurgeLogs();
self::CleanOrphanedFiles();
self::PurgeDrafts();
self::MaybeOptimizeTables();
}
}
?>
......@@ -147,11 +147,10 @@ class TicketLock {
return db_query($sql);
}
//Called via cron
//Called via cron
function cleanup() {
//Cleanup any expired locks.
db_query('DELETE FROM '.TICKET_LOCK_TABLE.' WHERE expire<NOW()');
@db_query('OPTIMIZE TABLE '.TICKET_LOCK_TABLE);
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment