MDL-42493 revert nasty DB meta caching hack that was trying to work around shutdown issues

The original problem was resolved via new core shutdown handler support.
This commit is contained in:
Petr Škoda
2013-10-25 21:20:06 +02:00
parent 68291f2d57
commit 302506e03a
7 changed files with 24 additions and 34 deletions
-16
View File
@@ -373,7 +373,6 @@ abstract class moodle_database {
$this->database_manager = null;
}
$this->tables = null;
$this->metacache = null;
}
/**
@@ -962,26 +961,11 @@ abstract class moodle_database {
*/
public function reset_caches() {
$this->tables = null;
$this->metacache = null;
// Purge MUC as well
$identifiers = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
cache_helper::purge_by_definition('core', 'databasemeta', $identifiers);
}
/**
* Call before using $this->metacache.
*
* Note: this is necessary because we want to write to database in shutdown handler
* and it needs to use the caches, but MUC would be already disposed.
*/
protected function init_caches() {
if ($this->metacache) {
return;
}
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$this->metacache = cache::make('core', 'databasemeta', $properties);
}
/**
* Returns the sql generator used for db manipulation.
* Used mostly in upgrade.php scripts.
+4 -3
View File
@@ -398,8 +398,9 @@ class mssql_native_moodle_database extends moodle_database {
public function get_columns($table, $usecache=true) {
if ($usecache) {
$this->init_caches();
if ($data = $this->metacache->get($table)) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}
@@ -495,7 +496,7 @@ class mssql_native_moodle_database extends moodle_database {
$this->free_result($result);
if ($usecache) {
$result = $this->metacache->set($table, $structure);
$cache->set($table, $structure);
}
return $structure;
+4 -3
View File
@@ -511,8 +511,9 @@ class mysqli_native_moodle_database extends moodle_database {
public function get_columns($table, $usecache=true) {
if ($usecache) {
$this->init_caches();
if ($data = $this->metacache->get($table)) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}
@@ -618,7 +619,7 @@ class mysqli_native_moodle_database extends moodle_database {
}
if ($usecache) {
$result = $this->metacache->set($table, $structure);
$cache->set($table, $structure);
}
return $structure;
+4 -3
View File
@@ -470,8 +470,9 @@ class oci_native_moodle_database extends moodle_database {
public function get_columns($table, $usecache=true) {
if ($usecache) {
$this->init_caches();
if ($data = $this->metacache->get($table)) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}
@@ -663,7 +664,7 @@ class oci_native_moodle_database extends moodle_database {
}
if ($usecache) {
$result = $this->metacache->set($table, $structure);
$cache->set($table, $structure);
}
return $structure;
+4 -3
View File
@@ -385,8 +385,9 @@ class pgsql_native_moodle_database extends moodle_database {
*/
public function get_columns($table, $usecache=true) {
if ($usecache) {
$this->init_caches();
if ($data = $this->metacache->get($table)) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}
@@ -569,7 +570,7 @@ class pgsql_native_moodle_database extends moodle_database {
pg_free_result($result);
if ($usecache) {
$result = $this->metacache->set($table, $structure);
$cache->set($table, $structure);
}
return $structure;
+4 -3
View File
@@ -201,8 +201,9 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database {
public function get_columns($table, $usecache=true) {
if ($usecache) {
$this->init_caches();
if ($data = $this->metacache->get($table)) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}
@@ -299,7 +300,7 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database {
}
if ($usecache) {
$result = $this->metacache->set($table, $structure);
$cache->set($table, $structure);
}
return $structure;
+4 -3
View File
@@ -462,8 +462,9 @@ class sqlsrv_native_moodle_database extends moodle_database {
*/
public function get_columns($table, $usecache = true) {
if ($usecache) {
$this->init_caches();
if ($data = $this->metacache->get($table)) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}
@@ -559,7 +560,7 @@ class sqlsrv_native_moodle_database extends moodle_database {
$this->free_result($result);
if ($usecache) {
$result = $this->metacache->set($table, $structure);
$cache->set($table, $structure);
}
return $structure;