Index: admin_config.php =================================================================== --- admin_config.php (revision 14636) +++ admin_config.php (working copy) @@ -24,6 +24,10 @@ 1 => 'event', ), + 'RegularEvents' => Array( + 'optimize_performance' => Array('EventName' => 'OnOptimizePerformance', 'RunInterval' => 86400, 'Type' => reAFTER), + ), + 'TitlePresets' => Array ( 'tree_root' => Array ('format' => '!la_section_overview!'), Index: admin_events_handler.php =================================================================== --- admin_events_handler.php (revision 14636) +++ admin_events_handler.php (working copy) @@ -1384,6 +1384,53 @@ $event->status = kEvent::erFAIL; } } + + /** + * 1. Delete all Debug files from system/.restricted folder (format debug_@977827436@.txt) + * 2. Run MySQL OPTIMIZE SQL one by one on all In-Portal tables (found by prefix). + * + * @param kEvent $event + */ + function OnOptimizePerformance(&$event) + { + $start_time = adodb_mktime(); + $active_sessions = array_flip( + $this->Conn->GetCol('SELECT SessionKey + FROM ' . TABLE_PREFIX. 'UserSession + WHERE LastAccessed > ' . adodb_mktime() + ) + ); + + $files = scandir(RESTRICTED); + $file_path = RESTRICTED.'/'; + foreach ($files AS $file_name) { + + if (!preg_match('#^debug_@([0-9]{9})@.txt$#', $file_name, $matches)) { + // not debug file + continue; + } + + $sid = $matches[1]; + + if (isset($active_sessions[$sid])) { + // debug file belongs to an active session + continue; + } + + if (filemtime($file_path.$file_name) > $start_time) { + // debug file is recently created (after sessions snapshot) + continue; + } + + @unlink($file_path.$file_name); + } + + $system_tables = $this->Conn->GetCol('SHOW TABLES LIKE "'.TABLE_PREFIX.'%"'); + + foreach ($system_tables AS $table_name) { + $this->Conn->Query('OPTIMIZE TABLE '.$table_name); + } + } }