diff options
author | Benaka <benakamoorthi@fastmail.fm> | 2014-10-02 07:15:05 +0400 |
---|---|---|
committer | Benaka <benakamoorthi@fastmail.fm> | 2014-10-02 07:15:05 +0400 |
commit | dd4253fca0250554f7a9c3848711914be238e424 (patch) | |
tree | fcf303928a3daa3797951ff1278cc621303ecdf7 /core | |
parent | c9670997ad57319109d638fd58aba58273a6596b (diff) | |
parent | d4e8f012cfc219d361255f7e8a0b4627f708d9d9 (diff) |
Merge pull request #6331 from piwik/db_test_case_optimize
Optimize DatabaseTestCase by creating DB and tables only once (like IntegrationTestCase) so travis build will be faster.
Diffstat (limited to 'core')
-rw-r--r-- | core/Db/Schema/Mysql.php | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php index 43a42f167d..45ff75b685 100644 --- a/core/Db/Schema/Mysql.php +++ b/core/Db/Schema/Mysql.php @@ -341,12 +341,9 @@ class Mysql implements SchemaInterface || $forceReload === true ) { $db = Db::get(); - $prefixTables = $this->getTablePrefix(); + $prefixTables = $this->getTablePrefixEscaped(); - // '_' matches any character; force it to be literal - $prefixTables = str_replace('_', '\_', $prefixTables); - - $allTables = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "%'"); + $allTables = $this->getAllExistingTables($prefixTables); // all the tables to be installed $allMyTables = $this->getTablesNames(); @@ -461,8 +458,8 @@ class Mysql implements SchemaInterface */ public function truncateAllTables() { - $tablesAlreadyInstalled = $this->getTablesInstalled($forceReload = true); - foreach ($tablesAlreadyInstalled as $table) { + $tables = $this->getAllExistingTables(); + foreach ($tables as $table) { Db::query("TRUNCATE `$table`"); } } @@ -489,4 +486,21 @@ class Mysql implements SchemaInterface return $dbName; } + + private function getAllExistingTables($prefixTables = false) + { + if (empty($prefixTables)) { + $prefixTables = $this->getTablePrefixEscaped(); + } + + return Db::get()->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "%'"); + } + + private function getTablePrefixEscaped() + { + $prefixTables = $this->getTablePrefix(); + // '_' matches any character; force it to be literal + $prefixTables = str_replace('_', '\_', $prefixTables); + return $prefixTables; + } } |