Commit 93dfd690 authored by Joël Pittet's avatar Joël Pittet 🥸 Committed by Damien McKenna
Browse files

Issue #3046235 by joelpittet: Slow query 'show table status' on menu rebuild.

parent 0a429d3a
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ Backup and Migrate 7.x-3.x-dev, xxxx-xx-xx
  code no longer loading.
#2507495 by BrankoC, DamienMcKenna: Update script to disable destinations
  affected by the email delivery change.
#3046235 by joelpittet: Slow query 'show table status' on menu rebuild.


Backup and Migrate 7.x-3.6, 2018-12-15
+55 −20
Changes for includes/destinations.db.mysql.inc: 55 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,28 @@ backup_migrate_include('destinations.db');
 * @ingroup backup_migrate_destinations
 */
class backup_migrate_destination_db_mysql extends backup_migrate_destination_db {

  /**
   * The table's data keyed by table name.
   *
   * @var array
   */
  protected static $tableData = array();

  /**
   * The tables keyed by name.
   *
   * @var array
   */
  protected static $tableNames = array();

  /**
   * The views keyed by name.
   *
   * @var array
   */
  protected static $viewNames = array();

  public function type_name() {
    return t("MySQL Database");
  }
@@ -268,22 +290,24 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
   * Get a list of tables in the database.
   */
  public function _get_table_names() {
    $out = array();
    foreach ($this->_get_tables() as $table) {
      $out[$table['name']] = $table['name'];
    if (empty(static::$tableNames)) {
      static::$tableNames = $this->query("SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'")
        ->fetchAllKeyed(0, 0);
    }
    return $out;

    return static::$tableNames;
  }

  /**
   * Get a list of views in the database.
   */
  public function _get_view_names() {
    $out = array();
    foreach ($this->_get_views() as $view) {
      $out[$view['name']] = $view['name'];
    if (empty(static::$viewNames)) {
      static::$viewNames = $this->query("SHOW FULL TABLES WHERE Table_Type = 'VIEW'")
        ->fetchAllKeyed(0, 0);
    }
    return $out;

    return static::$viewNames;
  }

  /**
@@ -307,20 +331,36 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
  }

  /**
   * Get a list of tables in the db.
   * Get a list of table and view data in the db.
   */
  public function _get_tables() {
    $out = array();
    // get auto_increment values and names of all tables.
    $tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
  protected function get_table_data() {
    if (empty(static::$tableData)) {
      $tables = $this->query('SHOW TABLE STATUS')
        ->fetchAll(PDO::FETCH_ASSOC);

      foreach ($tables as $table) {
      // Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
        // Lowercase the keys because between Drupal 7.12 and 7.13/14 the
        // default query behavior was changed.
        // See: http://drupal.org/node/1171866
        $table = array_change_key_case($table);
        static::$tableData[$table['name']] = $table;
      }
    }

    return static::$tableData;
  }

  /**
   * Get a list of tables in the db.
   */
  public function _get_tables() {
    $out = array();
    foreach ($this->get_table_data() as $table) {
      if (!empty($table['engine'])) {
        $out[$table['name']] = $table;
      }
    }

    return $out;
  }

@@ -329,12 +369,7 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
   */
  public function _get_views() {
    $out = array();
    // get auto_increment values and names of all tables.
    $tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
    foreach ($tables as $table) {
      // Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
      // See: http://drupal.org/node/1171866
      $table = array_change_key_case($table);
    foreach ($this->get_table_data() as $table) {
      if (empty($table['engine'])) {
        $out[$table['name']] = $table;
      }
+54 −20
Changes for includes/sources.db.mysql.inc: 54 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,28 @@ backup_migrate_include('sources.db');
 * @ingroup backup_migrate_destinations
 */
class backup_migrate_source_db_mysql extends backup_migrate_source_db {

  /**
   * The table's data keyed by table name.
   *
   * @var array
   */
  protected static $tableData = array();

  /**
   * The tables keyed by name.
   *
   * @var array
   */
  protected static $tableNames = array();

  /**
   * The views keyed by name.
   *
   * @var array
   */
  protected static $viewNames = array();

  public function type_name() {
    return t("MySQL Database");
  }
@@ -256,22 +278,24 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
   * Get a list of tables in the database.
   */
  public function _get_table_names() {
    $out = array();
    foreach ($this->_get_tables() as $table) {
      $out[$table['name']] = $table['name'];
    if (empty(static::$tableNames)) {
      static::$tableNames = $this->query("SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'")
        ->fetchAllKeyed(0, 0);
    }
    return $out;

    return static::$tableNames;
  }

  /**
   * Get a list of views in the database.
   */
  public function _get_view_names() {
    $out = array();
    foreach ($this->_get_views() as $view) {
      $out[$view['name']] = $view['name'];
    if (empty(static::$viewNames)) {
      static::$viewNames = $this->query("SHOW FULL TABLES WHERE Table_Type = 'VIEW'")
        ->fetchAllKeyed(0, 0);
    }
    return $out;

    return static::$viewNames;
  }

  /**
@@ -295,20 +319,35 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
  }

  /**
   * Get a list of tables in the db.
   * Get a list of table and view data in the db.
   */
  public function _get_tables() {
    $out = array();
    // get auto_increment values and names of all tables.
    $tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
  protected function get_table_data() {
    if (empty(static::$tableData)) {
      $tables = $this->query('SHOW TABLE STATUS')->fetchAll(PDO::FETCH_ASSOC);

      foreach ($tables as $table) {
      // Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
        // Lowercase the keys because between Drupal 7.12 and 7.13/14 the
        // default query behavior was changed.
        // See: http://drupal.org/node/1171866
        $table = array_change_key_case($table);
        static::$tableData[$table['name']] = $table;
      }
    }

    return static::$tableData;
  }

  /**
   * Get a list of tables in the db.
   */
  public function _get_tables() {
    $out = array();
    foreach ($this->get_table_data() as $table) {
      if (!empty($table['engine'])) {
        $out[$table['name']] = $table;
      }
    }

    return $out;
  }

@@ -317,12 +356,7 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
   */
  public function _get_views() {
    $out = array();
    // get auto_increment values and names of all tables.
    $tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
    foreach ($tables as $table) {
      // Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
      // See: http://drupal.org/node/1171866
      $table = array_change_key_case($table);
    foreach ($this->get_table_data() as $table) {
      if (empty($table['engine'])) {
        $out[$table['name']] = $table;
      }