You are here

function _optimizedb_clear_table in OptimizeDB 6

Cleaning table cache_form and cleaning time record.

Parameters

int $type: 0 - Delete cache which expired. 1 - Delete entire cache.

4 calls to _optimizedb_clear_table()
drush_optimizedb_cleaning in includes/optimizedb.drush.inc
Cleaning table cache_form.
optimizedb_admin_clear_table_all_submit in ./optimizedb.module
Implements hook_FORMID_submit().
optimizedb_admin_clear_table_submit in ./optimizedb.module
Implements hook_FORM_ID_submit().
optimizedb_cron in ./optimizedb.module
Implements hook_cron().

File

./optimizedb.module, line 696
Database Optimization.

Code

function _optimizedb_clear_table($type = NULL) {
  if (is_null($type)) {
    $type = variable_get('optimizedb_clear_type', 0);
  }
  if ((int) $type == 1) {
    db_query("TRUNCATE {cache_form}");
  }
  else {
    $count_all = (int) db_result(db_query("SELECT COUNT(*) FROM {cache_form}"));
    if ($count_all !== 0) {
      $count_expire = (int) db_result(db_query("SELECT COUNT(*) FROM {cache_form} WHERE expire < %d", OPTIMIZEDB_REQUEST_TIME));
      if ($count_all == $count_expire) {
        db_query("TRUNCATE {cache_form}");
      }
      else {
        db_query("DELETE FROM {cache_form} WHERE expire < %d", OPTIMIZEDB_REQUEST_TIME);
      }
    }
  }

  // Update size tables.
  _optimizedb_tables_list();
  variable_set('optimizedb_last_clear', OPTIMIZEDB_REQUEST_TIME);
}