]> git.mjollnir.org Git - moodle.git/commitdiff
Cache names for improved speed in long iterations requesting
authorstronk7 <stronk7>
Sun, 27 Aug 2006 08:52:51 +0000 (08:52 +0000)
committerstronk7 <stronk7>
Sun, 27 Aug 2006 08:52:51 +0000 (08:52 +0000)
the same name thousands of times.
Prepare Oracle Sequnces for the insert_record function.

lib/xmldb/classes/generators/XMLDBGenerator.class.php
lib/xmldb/classes/generators/oci8po/oci8po.class.php

index 7d9aafbc3822c02ade98d73d832516a54e27e47a..7a42a553cec9bd2ef6f973547926a9c7898d1c10 100644 (file)
@@ -390,10 +390,16 @@ class XMLDBgenerator {
         $name = '';
 
     /// Implement one basic cache to avoid object name duplication
+    /// and to speed up repeated queries for the same objects
         if (!isset($used_names)) {
             static $used_names = array();
         }
 
+    /// If this exact object has been requested, return it
+        if (array_key_exists($tablename.'-'.$fields.'-'.$suffix, $used_names)) {
+            return $used_names[$tablename.'-'.$fields.'-'.$suffix];
+        }
+
     /// Use standard naming. See http://docs.moodle.org/en/XMLDB_key_and_index_naming
         $tablearr = explode ('_', $tablename);
         foreach ($tablearr as $table) {
@@ -434,7 +440,7 @@ class XMLDBgenerator {
         }
 
     /// Add the name to the cache
-        $used_names[] = $namewithsuffix;
+        $used_names[$tablename.'-'.$fields.'-'.$suffix] = $namewithsuffix;
 
     /// Quote it if necessary (reserved words)
         $namewithsuffix = $this->getEncQuoted($namewithsuffix);
index e4a0a1bb83bf4748ba0ce1b31dc7e4f400499b3f..0a8f277999ed4129adf617c25e7edc96d13598d7 100644 (file)
@@ -138,7 +138,9 @@ class XMLDBoci8po extends XMLDBgenerator {
         $trigger.= "\nON " . $this->getEncQuoted($this->prefix . $xmldb_table->getName());
         $trigger.= "\n    FOR EACH ROW";
         $trigger.= "\nBEGIN";
-        $trigger.= "\n    SELECT " . $sequence_name . '.nextval INTO :new.' . $this->getEncQuoted($xmldb_field->getName()) . " FROM dual;";
+        $trigger.= "\n    IF :old." . $this->getEncQuoted($xmldb_field->getName()) . ' IS NOT NULL THEN';
+        $trigger.= "\n        SELECT " . $sequence_name . '.nextval INTO :new.' . $this->getEncQuoted($xmldb_field->getName()) . " FROM dual;";
+        $trigger.= "\n    END IF;";
         $trigger.= "\nEND;";
         return array($sequence, $trigger);
     }