]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14974 improved columns caching implementation
authorskodak <skodak>
Sun, 25 May 2008 09:31:38 +0000 (09:31 +0000)
committerskodak <skodak>
Sun, 25 May 2008 09:31:38 +0000 (09:31 +0000)
lib/ddl/database_manager.php
lib/ddl/mssql_sql_generator.php
lib/ddl/mysql_sql_generator.php
lib/ddl/oracle_sql_generator.php
lib/ddl/postgres_sql_generator.php
lib/deprecatedlib.php
lib/dml/adodb_moodle_database.php
lib/dml/moodle_database.php
lib/dml/pdo_moodle_database.php
lib/dml/postgres7_adodb_moodle_database.php
lib/dmllib_todo.php

index da7f2830faf1bc9eb4aa000013a108d79fab0758..67451235e7ce9ddfe8006e6dad4ec4b58283ce77 100644 (file)
@@ -84,8 +84,6 @@ class database_manager {
             notify('<strong>' . get_string('error') . '</strong>');
         }
 
-        $this->mdb->reset_columns();  // Clear out the cache, just in case changes were made to table structures
-
         return $result;
     }
 
@@ -150,8 +148,7 @@ class database_manager {
         }
 
     /// Get list of fields in table
-        $this->mdb->reset_columns($tablename); // better reset before testing
-        $columns = $this->mdb->get_columns($tablename);
+        $columns = $this->mdb->get_columns($tablename, false);
 
         $exists = array_key_exists($fieldname,  $columns);
 
index 7cac0db09c4210ba237cfa6f3cb9c273746c8455..4616240d74332a2e97756ced13b48f4b8bda362c 100644 (file)
@@ -325,9 +325,7 @@ class mssql_sql_generator extends sql_generator {
         $fieldname = $xmldb_field->getName();
 
     /// Take a look to field metadata
-        $this->mdb->reset_columns($tablename);
-
-        $meta = $this->mdb->get_columns($tablename);
+        $meta = $this->mdb->get_columns($tablename, false);
         $metac = $meta[$fieldname];
         $oldmetatype = $metac->meta_type;
 
index a1e37ed4a46c1e7cd7739495f564168964c61870..4ccab7c65bc075111d931f730136ab1aa62ea3b1 100644 (file)
@@ -255,14 +255,10 @@ class mysql_sql_generator extends sql_generator {
      */
     public function getCheckConstraintsFromDB($xmldb_table, $xmldb_field = null) {
 
-        global $db;
-
         $tablename = $xmldb_table->getName($xmldb_table);
 
-        $this->mdb->reset_columns($tablename);
-
     /// Fetch all the columns in the table
-        if (!$columns = $this->mdb->get_columns($tablename)) {
+        if (!$columns = $this->mdb->get_columns($tablename, false)) {
             return array();
         }
 
index 05c323cdc5f6174f163cb91cbb432f65e1664e85..ba6324109c2a126ae368a7b6de514ea305f2ba5b 100644 (file)
@@ -338,7 +338,7 @@ class oracle_sql_generator extends sql_generator {
         $fieldname = $xmldb_field->getName();
 
     /// Take a look to field metadata
-        $meta = $this->mdb->get_columns($xmldb_table->getName());
+        $meta = $this->mdb->get_columns($tablename, false);
         $metac = $meta[$fieldname];
         $oldmetatype = $metac->meta_type;
 
index 77890f6769d46009c37ff953311c82dc9ca21dd4..ccd1ca78dca21678d4c640d26665f68024d69368 100644 (file)
@@ -246,7 +246,7 @@ class postgres_sql_generator extends sql_generator {
         $fieldname = $xmldb_field->getName();
 
     /// Take a look to field metadata
-        $meta = $this->mdb->get_columns($xmldb_table->getName());
+        $meta = $this->mdb->get_columns($tablename, false);
         $metac = $meta[$xmldb_field->getName()];
         $oldmetatype = $metac->meta_type;
         $oldlength = $metac->max_length;
index 02f72e450c4372e6f42ed864c85db76fa886b11f..b8c77332b8090ff3fe187fee84d4410c89ed07e3 100644 (file)
@@ -480,6 +480,20 @@ function get_course_users($courseid, $sort='ul.timeaccess DESC', $exceptions='',
 
 }
 
+/**
+ * Returns a list of all site users
+ * Obsolete, just calls get_course_users(SITEID)
+ *
+ * @uses SITEID
+ * @deprecated Use {@link get_course_users()} instead.
+ * @param string $fields A comma separated list of fields to be returned from the chosen table.
+ * @return object|false  {@link $USER} records or false if error.
+ */
+function get_site_users($sort='u.lastaccess DESC', $fields='*', $exceptions='') {
+
+    return get_course_users(SITEID, $sort, $exceptions, $fields);
+}
+
 /**
  * Returns an array of user objects
  *
index 9bd9f03ffd4326891cbfd6337dcbde0dafcad7cb..76548fa27082558f7db34d71b7a93f3cccfdf8cd 100644 (file)
@@ -10,7 +10,6 @@ require_once($CFG->libdir.'/dml/adodb_moodle_recordset.php');
 abstract class adodb_moodle_database extends moodle_database {
 
     protected $db;
-    protected $columns = array(); // I wish we had a shared memory cache for this :-(
 
     /**
      * Returns localised database type name
@@ -137,8 +136,8 @@ abstract class adodb_moodle_database extends moodle_database {
         return $indexes;
     }
 
-    public function get_columns($table) {
-        if (isset($this->columns[$table])) {
+    public function get_columns($table, $usecache=true) {
+        if ($usecache and isset($this->columns[$table])) {
             return $this->columns[$table];
         }
 
@@ -157,14 +156,6 @@ abstract class adodb_moodle_database extends moodle_database {
         return $this->columns[$table];
     }
 
-    public function reset_columns($table=null) {
-        if ($table) {
-            unset($this->columns[$table]);
-        } else {
-            $this->columns[$table] = array();
-        }
-    }
-
     public function get_last_error() {
         return $this->db->ErrorMsg();
     }
@@ -206,6 +197,8 @@ abstract class adodb_moodle_database extends moodle_database {
             $result = false;
             $this->report_error($sql);
         }
+        // structure changed, reset columns cache
+        $this->reset_columns();
         return $result;
     }
 
index 484b51325caf0d4b9cace6c09f5f8527750ce92d..cbcd8d877f060b08b22b660156c97551d60936fd 100644 (file)
@@ -9,6 +9,8 @@ abstract class moodle_database {
     // manipulates the db structure
     protected $database_manager;
 
+    protected $columns = array(); // I wish we had a shared memory cache for this :-(
+
     // db connection options
     protected $dbhost;
     protected $dbuser;
@@ -319,16 +321,19 @@ abstract class moodle_database {
     /**
      * Returns datailed information about columns in table. This information is cached internally.
      * @param string $table name
+     * @param bool $usecache
      * @return array array of database_column_info objects indexed with column names
      */
-    public abstract function get_columns($table);
+    public abstract function get_columns($table, $usecache=true);
 
     /**
      * Reset internal column details cache
      * @param string $table - empty means all, or one if name of table given
      * @return void
      */
-    public abstract function reset_columns($table=null);
+    public function reset_columns() {
+        $this->columns[] = array();
+    }
 
     /**
      * Returns sql generator used for db manipulation.
index bcb1c4cc4c170f977dc78c8d4f6cc27cbe7ebd1a..81497a4a3ae90ef8bf56735e620536036b3700e2 100644 (file)
@@ -10,7 +10,6 @@ require_once($CFG->libdir.'/dml/pdo_moodle_recordset.php');
 abstract class pdo_moodle_database extends moodle_database {
 
     protected $pdb;
-    protected $columns = array(); // I wish we had a shared memory cache for this :-(
 
     //TODO: This looks incorrect now IMO. Construct should have only external and connect get all the rest of params
     public function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null, $external=false) {
@@ -31,8 +30,8 @@ abstract class pdo_moodle_database extends moodle_database {
     protected function configure_dbconnection() {
     }
 
-    public function get_columns($table) {
-        if (isset($this->columns[$table])) {
+    public function get_columns($table, $usecache=true) {
+        if ($usecache and isset($this->columns[$table])) {
             return $this->columns[$table];
         }
 
@@ -43,15 +42,6 @@ abstract class pdo_moodle_database extends moodle_database {
         return $this->columns[$table];
     }
 
-    public function reset_columns($table=null) {
-        if ($table) {
-            unset($this->columns[$table]);
-        } else {
-            $this->columns[$table] = array();
-        }
-    }
-
-
     protected function report_error($sql, $params, $obj) {
         debugging($e->getMessage() .'<br /><br />'. s($sql));
     }
@@ -66,7 +56,6 @@ abstract class pdo_moodle_database extends moodle_database {
 
     public function execute($sql, array $params=null) {
         try {
-            //$this->reset_columns(); // TODO: do we need to clean the cache here??
             list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
             $sth = $this->dbh->prepare($sql);
             return $sth->execute($params);
index 6ce794e7023afc9a690e5d549ecbbb49a8b9bdd9..92d544c157b726087345792d28b658c1d8d9e9b5 100644 (file)
@@ -100,8 +100,8 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
         return SQL_PARAMS_QM;
     }
 
-    public function get_columns($table) {
-        if (isset($this->columns[$table])) {
+    public function get_columns($table, $usecache=true) {
+        if ($usecache and isset($this->columns[$table])) {
             return $this->columns[$table];
         }
 
index a4fbb097325085fb77d4d54aa79a8e0e1ddb4c2b..3b0476997da29c446b9b15e6118f7781338ec511 100644 (file)
@@ -39,12 +39,12 @@ function execute_sql($command, $feedback=true) {
         }
     }
 
-    $DB->reset_columns();  // Clear out the cache, just in case changes were made to table structures
-
     if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
 
     $rs = $db->Execute($command);
 
+    $DB->reset_columns();  // Clear out the cache, just in case changes were made to table structures
+
     $db->debug = $olddebug;
 
     if ($rs) {