Skip to content

Commit

Permalink
MDL-39389 add databasemeta cache to ms/oci drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 28, 2013
1 parent cf5a329 commit 9043466
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
19 changes: 14 additions & 5 deletions lib/dml/mssql_native_moodle_database.php
Expand Up @@ -410,11 +410,16 @@ public function get_indexes($table) {
* @return array array of database_column_info objects indexed with column names
*/
public function get_columns($table, $usecache=true) {
if ($usecache and isset($this->columns[$table])) {
return $this->columns[$table];

if ($usecache) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}

$this->columns[$table] = array();
$structure = array();

if (!$this->temptables->is_temptable($table)) { // normal table, get metadata from own schema
$sql = "SELECT column_name AS name,
Expand Down Expand Up @@ -494,11 +499,15 @@ public function get_columns($table, $usecache=true) {
// Process binary
$info->binary = $info->meta_type == 'B' ? true : false;

$this->columns[$table][$info->name] = new database_column_info($info);
$structure[$info->name] = new database_column_info($info);
}
$this->free_result($result);

return $this->columns[$table];
if ($usecache) {
$result = $cache->set($table, $structure);
}

return $structure;
}

/**
Expand Down
19 changes: 14 additions & 5 deletions lib/dml/oci_native_moodle_database.php
Expand Up @@ -469,15 +469,20 @@ public function get_indexes($table) {
* @return array array of database_column_info objects indexed with column names
*/
public function get_columns($table, $usecache=true) {
if ($usecache and isset($this->columns[$table])) {
return $this->columns[$table];

if ($usecache) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}

if (!$table) { // table not specified, return empty array directly
return array();
}

$this->columns[$table] = array();
$structure = array();

// We give precedence to CHAR_LENGTH for VARCHAR2 columns over WIDTH because the former is always
// BYTE based and, for cross-db operations, we want CHAR based results. See MDL-29415
Expand Down Expand Up @@ -656,10 +661,14 @@ public function get_columns($table, $usecache=true) {
$info->meta_type = '?';
}

$this->columns[$table][$info->name] = new database_column_info($info);
$structure[$info->name] = new database_column_info($info);
}

if ($usecache) {
$result = $cache->set($table, $structure);
}

return $this->columns[$table];
return $structure;
}

/**
Expand Down
18 changes: 13 additions & 5 deletions lib/dml/sqlsrv_native_moodle_database.php
Expand Up @@ -476,11 +476,15 @@ public function get_indexes($table) {
* @return array array of database_column_info objects indexed with column names
*/
public function get_columns($table, $usecache = true) {
if ($usecache and isset($this->columns[$table])) {
return $this->columns[$table];
if ($usecache) {
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
$cache = cache::make('core', 'databasemeta', $properties);
if ($data = $cache->get($table)) {
return $data;
}
}

$this->columns[$table] = array ();
$structure = array();

if (!$this->temptables->is_temptable($table)) { // normal table, get metadata from own schema
$sql = "SELECT column_name AS name,
Expand Down Expand Up @@ -560,11 +564,15 @@ public function get_columns($table, $usecache = true) {
// Process binary
$info->binary = $info->meta_type == 'B' ? true : false;

$this->columns[$table][$info->name] = new database_column_info($info);
$structure[$info->name] = new database_column_info($info);
}
$this->free_result($result);

return $this->columns[$table];
if ($usecache) {
$result = $cache->set($table, $structure);
}

return $structure;
}

/**
Expand Down

0 comments on commit 9043466

Please sign in to comment.