Hi,
I like the idea of this module. I've had a similar module I wrote sitting around on my HD that just runs OPTIMIZE (for MySQL) or VACUUM (for PGSQL) to clean up the database every so often. Similar functionality is in the Database Administration module, but you have to explicitly choose which tables to optimize, whereas the module I wrote automatically looks for tables that need optimizing and just optimizes those.
The code is fairly short, and I think it fits in pretty well with the purpose of this module, so I figured I'd post it here. If you want to keep it, great; if not, that's fine too.
/**
* Implementation of hook_cron().
*/
function dbopt_cron() {
//Optimize every 6 hours. Ideally this would be a setting.
if (variable_get('dbopt_last', 0) < time() - 60 * 60 * 6) {
//This is not in the SQL standards, so PGSQL and MySQL have their own commands for it.
switch ($GLOBALS['db_type']) {
case 'pgsql':
//I don't run any sites on PGSQL so I haven't actually tested this, but the documentation indicates it should work.
db_query("VACUUM");
break;
case 'mysqli':
case 'mysql':
$tables = dbopt_get_tables(TRUE);
$tables = implode(',', $tables);
$result = db_query("OPTIMIZE TABLE $tables");
break;
watchdog('dbopt', 'Database tables optimized');
variable_set('dbopt_last', time());
}
}
/**
* Gets a list of tables and returns them in an array.
*/
function dbopt_get_tables() {
$result = db_query("SHOW TABLE STATUS");
$values = array();
while ($table = db_fetch_array($result)) {
if ($table['Data_free']) {
$values[] = $table['Name'];
}
}
return $values;
}
Closed: won't fix
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.