mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-17859 implemented caching in get_tables()
This commit is contained in:
parent
1045a0074c
commit
117679db37
@ -345,7 +345,7 @@ class mysql_sql_generator extends sql_generator {
|
||||
$tablename = $xmldb_table->getName($xmldb_table);
|
||||
|
||||
/// Fetch all the columns in the table
|
||||
if (!$columns = $this->mdb->get_columns($tablename, false)) {
|
||||
if (!$columns = $this->mdb->get_columns($tablename)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||
* Return tables in database WITHOUT current prefix
|
||||
* @return array of table names in lowercase and without prefix
|
||||
*/
|
||||
public function get_tables() {
|
||||
public function get_tables($usecache=true) {
|
||||
$this->query_start("--adodb-MetaTables", null, SQL_QUERY_AUX);
|
||||
$metatables = $this->adodb->MetaTables();
|
||||
$this->query_end(true);
|
||||
@ -192,7 +192,7 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||
* @throws dml_exception if error
|
||||
*/
|
||||
public function change_database_structure($sql) {
|
||||
$this->reset_columns();
|
||||
$this->reset_caches();
|
||||
|
||||
$this->query_start($sql, null, SQL_QUERY_STRUCTURE);
|
||||
$rs = $this->adodb->Execute($sql);
|
||||
|
@ -40,6 +40,7 @@ abstract class moodle_database {
|
||||
protected $database_manager;
|
||||
|
||||
protected $columns = array(); // I wish we had a shared memory cache for this :-(
|
||||
protected $tables = null;
|
||||
|
||||
// db connection options
|
||||
protected $dbhost;
|
||||
@ -246,6 +247,7 @@ abstract class moodle_database {
|
||||
$this->database_manager = null;
|
||||
}
|
||||
$this->columns = array();
|
||||
$this->tables = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -606,7 +608,7 @@ abstract class moodle_database {
|
||||
* Return tables in database WITHOUT current prefix
|
||||
* @return array of table names in lowercase and without prefix
|
||||
*/
|
||||
public abstract function get_tables();
|
||||
public abstract function get_tables($usecache=true);
|
||||
|
||||
/**
|
||||
* Return table indexes - everything lowercased
|
||||
@ -627,8 +629,9 @@ abstract class moodle_database {
|
||||
* @param string $table - empty means all, or one if name of table given
|
||||
* @return void
|
||||
*/
|
||||
public function reset_columns() {
|
||||
public function reset_caches() {
|
||||
$this->columns = array();
|
||||
$this->tables = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,8 +177,11 @@ class mysqli_native_moodle_database extends moodle_database {
|
||||
* Return tables in database WITHOUT current prefix
|
||||
* @return array of table names in lowercase and without prefix
|
||||
*/
|
||||
public function get_tables() {
|
||||
$tables = array();
|
||||
public function get_tables($usecache=true) {
|
||||
if ($usecache and $this->tables !== null) {
|
||||
return $this->tables;
|
||||
}
|
||||
$this->tables = array();
|
||||
$sql = "SHOW TABLES";
|
||||
$this->query_start($sql, null, SQL_QUERY_AUX);
|
||||
$result = $this->mysqli->query($sql);
|
||||
@ -192,11 +195,11 @@ class mysqli_native_moodle_database extends moodle_database {
|
||||
}
|
||||
$tablename = substr($tablename, strlen($this->prefix));
|
||||
}
|
||||
$tables[$tablename] = $tablename;
|
||||
$this->tables[$tablename] = $tablename;
|
||||
}
|
||||
$result->close();
|
||||
}
|
||||
return $tables;
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -393,7 +396,7 @@ class mysqli_native_moodle_database extends moodle_database {
|
||||
* @throws dml_exception if error
|
||||
*/
|
||||
public function change_database_structure($sql) {
|
||||
$this->reset_columns();
|
||||
$this->reset_caches();
|
||||
|
||||
$this->query_start($sql, null, SQL_QUERY_STRUCTURE);
|
||||
$result = $this->mysqli->query($sql);
|
||||
|
@ -235,7 +235,7 @@ class oci_native_moodle_database extends moodle_database {
|
||||
* Return tables in database WITHOUT current prefix
|
||||
* @return array of table names in lowercase and without prefix
|
||||
*/
|
||||
public function get_tables() {
|
||||
public function get_tables($usecache=true) {
|
||||
$tables = array();
|
||||
$prefix = str_replace('_', "\\_", strtoupper($this->prefix));
|
||||
$sql = "SELECT TABLE_NAME
|
||||
@ -516,7 +516,7 @@ class oci_native_moodle_database extends moodle_database {
|
||||
* @throws dml_exception if error
|
||||
*/
|
||||
public function change_database_structure($sql) {
|
||||
$this->reset_columns();
|
||||
$this->reset_caches();
|
||||
|
||||
$this->query_start($sql, null, SQL_QUERY_STRUCTURE);
|
||||
$stmt = $this->parse_query($sql);
|
||||
|
@ -151,7 +151,7 @@ abstract class pdo_moodle_database extends moodle_database {
|
||||
$this->debug_query($sql);
|
||||
}
|
||||
$this->pdb->exec($sql);
|
||||
$this->reset_columns();
|
||||
$this->reset_caches();
|
||||
return true;
|
||||
} catch (PDOException $ex) {
|
||||
$this->lastError = $ex->getMessage();
|
||||
|
@ -228,8 +228,11 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
* Return tables in database WITHOUT current prefix
|
||||
* @return array of table names in lowercase and without prefix
|
||||
*/
|
||||
public function get_tables() {
|
||||
$tables = array();
|
||||
public function get_tables($usecache=true) {
|
||||
if ($usecache and $this->tables !== null) {
|
||||
return $this->tables;
|
||||
}
|
||||
$this->tables = array();
|
||||
$prefix = str_replace('_', '\\\\_', $this->prefix);
|
||||
$sql = "SELECT tablename
|
||||
FROM pg_catalog.pg_tables
|
||||
@ -245,11 +248,11 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
continue;
|
||||
}
|
||||
$tablename = substr($tablename, strlen($this->prefix));
|
||||
$tables[$tablename] = $tablename;
|
||||
$this->tables[$tablename] = $tablename;
|
||||
}
|
||||
pg_free_result($result);
|
||||
}
|
||||
return $tables;
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -493,7 +496,7 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
* @throws dml_exception if error
|
||||
*/
|
||||
public function change_database_structure($sql) {
|
||||
$this->reset_columns();
|
||||
$this->reset_caches();
|
||||
|
||||
$this->query_start($sql, null, SQL_QUERY_STRUCTURE);
|
||||
$result = pg_query($this->pgsql, $sql);
|
||||
|
@ -1964,7 +1964,7 @@ class moodle_database_for_testing extends moodle_database {
|
||||
public function get_server_info(){}
|
||||
protected function allowed_param_types(){}
|
||||
public function get_last_error(){}
|
||||
public function get_tables(){}
|
||||
public function get_tables($usecache=true){}
|
||||
public function get_indexes($table){}
|
||||
public function get_columns($table, $usecache=true){}
|
||||
public function set_debug($state){}
|
||||
|
@ -108,7 +108,7 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database {
|
||||
* Return tables in database WITHOUT current prefix
|
||||
* @return array of table names in lowercase and without prefix
|
||||
*/
|
||||
public function get_tables() {
|
||||
public function get_tables($usecache=true) {
|
||||
$tables = array();
|
||||
|
||||
$sql = 'SELECT name FROM sqlite_master WHERE type="table" UNION ALL SELECT name FROM sqlite_temp_master WHERE type="table" ORDER BY name';
|
||||
|
Loading…
x
Reference in New Issue
Block a user