Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This is a massive speed increase in journal_get_users_done.

The fix requires UNION support in the database.  I've added a simple little
test to see if UNION queries work.

This change very much needs to be tested out by someone using MySQL 3.  If
it tests out there successfully, the supports_union code should be moved out
of this file and into datalib.  Ideally, someone will extend that test and
creatle get_records_union_sql, a function that would split up UNION queries
for databases that don't support them and do an array_merge (and proper
sorting, which is missing from my fix) on the result sets.
  • Loading branch information...
commit dcfa857df2847a58424770cf6c5f4438deb5365c 1 parent 665ec94
gregb_cc authored
Showing with 52 additions and 10 deletions.
  1. +52 −10 mod/journal/lib.php
View
62 mod/journal/lib.php
@@ -283,19 +283,61 @@ function journal_get_participants($journalid) {
}
// SQL FUNCTIONS ///////////////////////////////////////////////////////////////////
+function supports_union(){
+ # not all databases support UNION. Adodb doesn't seem to keep track of which do.
+ # this function should probably be moved to datalib once it has been thouroughly tested.
+ $qry = "SELECT 'a' as a UNION SELECT 'b' as a'";
+ $test = get_records_sql($qry);
+ return ($test['b']->a = 'b');
+ }
function journal_get_users_done($journal) {
global $CFG;
- return get_records_sql("SELECT u.*
- FROM {$CFG->prefix}user u,
- {$CFG->prefix}user_students s,
- {$CFG->prefix}user_teachers t,
- {$CFG->prefix}journal_entries j
- WHERE ((s.course = '$journal->course' AND s.userid = u.id)
- OR (t.course = '$journal->course' AND t.userid = u.id))
- AND u.id = j.userid
- AND j.journal = '$journal->id'
- ORDER BY j.modified DESC");
+ if(supports_union()) {
+ # Yay! The database supports UNION, so we can use this fast query
+ return get_records_sql ("(SELECT u.*, j.modified
+ FROM {$CFG->prefix}journal_entries j,
+ {$CFG->prefix}user u,
+ {$CFG->prefix}user_students s
+ WHERE j.userid = u.id
+ AND s.userid = u.id
+ AND j.journal = $journal->id
+ AND s.course = $journal->course)
+
+ UNION
+
+ (SELECT u.*, j.modified
+ FROM {$CFG->prefix}journal_entries j,
+ {$CFG->prefix}user u,
+ {$CFG->prefix}user_teachers t
+ WHERE j.userid = u.id
+ AND t.userid = u.id
+ AND j.journal = $journal->id
+ AND t.course = $journal->course)
+ ORDER BY j.modified DESC");
+ } else {
+ # Poo! The database doesn't support UNION, so we are going to use this ugly hack
+ $s_journals = get_records_sql ("SELECT u.*
+ FROM {$CFG->prefix}journal_entries j,
+ {$CFG->prefix}user u,
+ {$CFG->prefix}user_students s
+ WHERE j.userid = u.id
+ AND s.userid = u.id
+ AND j.journal = $journal->id
+ AND s.course = $journal->course
+ ORDER BY j.modified DESC");
+
+ $t_journals = get_records_sql ("SELECT u.*
+ FROM {$CFG->prefix}journal_entries j,
+ {$CFG->prefix}user u,
+ {$CFG->prefix}user_teachers t
+ WHERE j.userid = u.id
+ AND t.userid = u.id
+ AND j.journal = $journal->id
+ AND t.course = $journal->course)
+ ORDER BY j.modified DESC");
+ return(array_merge($s_journals, $t_journals));
+ }
}
function journal_get_unmailed_graded($cutofftime) {
Please sign in to comment.
Something went wrong with that request. Please try again.