Skip to content

Commit

Permalink
MDL-21015 - add optional xmldb_structure cache in the install_one_tab…
Browse files Browse the repository at this point in the history
…le_from_xmldb_file()

method. 100x speedup for UnitTestCaseUsingDatabase tests. Defaults to false (old behaviour)
  • Loading branch information
stronk7 committed Dec 1, 2009
1 parent 3d99b4a commit a97c0dd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/ddl/database_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,21 @@ public function install_from_xmldb_file($file) {
*
* @param $file full path to the XML file to be used
* @param $tablename the name of the table.
* @param bool $cachestructures boolean to decide if loaded xmldb structures can be safely cached
* useful for testunits loading the enormous main xml file hundred of times (100x)
*/
public function install_one_table_from_xmldb_file($file, $tablename) {
$xmldb_file = $this->load_xmldb_file($file);
$xmldb_structure = $xmldb_file->getStructure();
public function install_one_table_from_xmldb_file($file, $tablename, $cachestructures = false) {

static $xmldbstructurecache = array(); // To store cached structures
if (!empty($xmldbstructurecache) && array_key_exists($file, $xmldbstructurecache)) {
$xmldb_structure = $xmldbstructurecache[$file];
} else {
$xmldb_file = $this->load_xmldb_file($file);
$xmldb_structure = $xmldb_file->getStructure();
if ($cachestructures) {
$xmldbstructurecache[$file] = $xmldb_structure;
}
}

$targettable = $xmldb_structure->getTable($tablename);
if (is_null($targettable)) {
Expand Down

0 comments on commit a97c0dd

Please sign in to comment.