]> git.mjollnir.org Git - moodle.git/commitdiff
optimization fo the removal of orphan records
authorgbateson <gbateson>
Fri, 28 Apr 2006 01:37:17 +0000 (01:37 +0000)
committergbateson <gbateson>
Fri, 28 Apr 2006 01:37:17 +0000 (01:37 +0000)
mod/hotpot/db/mysql.php
mod/hotpot/db/postgres7.php
mod/hotpot/db/update_to_v2.php
mod/hotpot/version.php

index bf4234dcbd64997cd3c324928842ca56654e7e96..9b7ee1ba55e1cdad4ba2c71bf6297ca79fc62564 100644 (file)
@@ -33,7 +33,7 @@ function hotpot_upgrade($oldversion) {
                require_once $update_to_v2;
                $ok = $ok && hotpot_update_to_v2_1_17();
        }
-       if ($oldversion < 2006042801) {
+       if ($oldversion < 2006042802) {
                require_once $update_to_v2;
                $ok = $ok && hotpot_update_to_v2_1_18();
        }
index 63baf900d8e20d7df940c340dc4caa34743a8a2f..8c7a3e8d3ab660452e57783efc6dc26faee05997 100644 (file)
@@ -37,7 +37,7 @@ function hotpot_upgrade($oldversion) {
                require_once $update_to_v2;
                $ok = $ok && hotpot_update_to_v2_1_17();
        }
-       if ($oldversion < 2006042801) {
+       if ($oldversion < 2006042802) {
                require_once $update_to_v2;
                $ok = $ok && hotpot_update_to_v2_1_18();
        }
index d5b33eaa427163df2f2f16eaa18c91bdf3ba3cda..cd578f34b9de16e0230baa5361402dfab9463327 100644 (file)
@@ -12,7 +12,7 @@ function hotpot_update_to_v2_1_18() {
 
        return $ok;
 }
-function hotpot_remove_orphans($secondarytable, $secondarykeyfield, $primarytable) {
+function hotpot_remove_orphans($secondarytable, $secondarykeyfield, $primarytable, $primarykeyfield='id') {
        global $CFG,$db;
        $ok = true;
 
@@ -22,23 +22,21 @@ function hotpot_remove_orphans($secondarytable, $secondarykeyfield, $primarytabl
 
        $records = get_records_sql("
                SELECT 
-                       t2.id, t2.id
+                       t2.$secondarykeyfield, t2.$secondarykeyfield
                FROM 
                        {$CFG->prefix}$secondarytable AS t2 LEFT JOIN {$CFG->prefix}$primarytable AS t1 
                        ON (t2.$secondarykeyfield = t1.id)
                WHERE 
-                       t1.id IS NULL
-               ORDER BY 
-                       t2.id
+                       t1.$primarykeyfield IS NULL
        ");
 
        // restore SQL message echo setting
        $db->debug = $debug;
 
        if ($records) {
-               $ids = implode(',', array_keys($records));
-               print 'removing '.count($records)." orphan record(s) from {$CFG->prefix}$secondarytable<br>";
-               $ok = $ok && execute_sql("DELETE FROM {$CFG->prefix}$secondarytable WHERE $secondarykeyfield IN ($ids)");
+               $keys = implode(',', array_keys($records));
+               print "removing orphan record(s) from {$CFG->prefix}$secondarytable<br>";
+               $ok = $ok && execute_sql("DELETE FROM {$CFG->prefix}$secondarytable WHERE $secondarykeyfield IN ($keys)");
        }
 
        return $ok;
index b8bfff228ca0f6abbb8115f2806015f1c065c653..a596514fc1925d9225d444d165e1cb2bd60b513e 100644 (file)
@@ -3,7 +3,7 @@
 ///  Code fragment to define the version of hotpot
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
-$module->version  = 2006042801;  // release date of this version (see note below)
+$module->version  = 2006042802;  // release date of this version (see note below)
 $module->release  = 'v2.1.18';    // human-friendly version name (used in mod/hotpot/lib.php)
 $module->cron     = 0;           // period for cron to check this module (secs)
 // interpretation of YYYYMMDDXY version numbers