Skip to content

Commit

Permalink
optimization fo the removal of orphan records
Browse files Browse the repository at this point in the history
  • Loading branch information
gbateson committed Apr 28, 2006
1 parent 9f02edc commit 8955d22
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mod/hotpot/db/mysql.php
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion mod/hotpot/db/postgres7.php
Expand Up @@ -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();
}
Expand Down
14 changes: 6 additions & 8 deletions mod/hotpot/db/update_to_v2.php
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mod/hotpot/version.php
Expand Up @@ -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
Expand Down

0 comments on commit 8955d22

Please sign in to comment.