Skip to content
Permalink
Browse files

Remove dead code and reduce # of times tables are listed.

There is no reason to get the table list for each and every fixture
creation. The important part - the original tables - is unlikely.

This should help improve performance on apps with many tables, as you
shave N queries per test method which can all add up.
  • Loading branch information...
markstory committed Sep 5, 2014
1 parent f7868a7 commit 12583197825e71562d2e3299dab88a7763566634
Showing with 4 additions and 12 deletions.
  1. +4 −12 src/TestSuite/Fixture/FixtureManager.php
@@ -184,24 +184,15 @@ protected function _loadFixtures($test) {
*
* @param \Cake\TestSuite\Fixture\TestFixture $fixture the fixture object to create
* @param Connection $db the datasource instance to use
* @param array $sources The existing tables in the datasource.
* @param bool $drop whether drop the fixture if it is already created or not
* @return void
*/
protected function _setupTable(TestFixture $fixture, Connection $db = null, $drop = true) {
if (!$db) {
if (!empty($fixture->connection)) {
$db = ConnectionManager::get($fixture->connection, false);
}
if (!$db) {
$db = ConnectionManager::get('test', false);
}
}
protected function _setupTable(TestFixture $fixture, Connection $db, array $sources, $drop = true) {
if (!empty($fixture->created) && in_array($db->configName(), $fixture->created)) {
return;
}
$schemaCollection = $db->schemaCollection();
$sources = (array)$schemaCollection->listTables();
$table = $fixture->table;
$exists = in_array($table, $sources);
@@ -243,9 +234,10 @@ public function load($test) {
foreach ($dbs as $db => $fixtures) {
$db = ConnectionManager::get($fixture->connection, false);
$db->transactional(function($db) use ($fixtures, $test) {
$tables = $db->schemaCollection()->listTables();
foreach ($fixtures as $fixture) {
if (!in_array($db->configName(), (array)$fixture->created)) {
$this->_setupTable($fixture, $db, $test->dropTables);
$this->_setupTable($fixture, $db, $tables, $test->dropTables);
}
if (!$test->dropTables) {
$fixture->truncate($db);

0 comments on commit 1258319

Please sign in to comment.
You can’t perform that action at this time.