From 59bc89851d2f3d948d3353ce3b4975e070e054e8 Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Mon, 2 Aug 2010 13:49:55 +1200 Subject: [PATCH 5/5] Participation report - MAJOR performance improvements --- course/report/participation/index.php | 17 +++++++---------- 1 files changed, 7 insertions(+), 10 deletions(-) diff --git a/course/report/participation/index.php b/course/report/participation/index.php index 9d05f59..5104f6e 100644 --- a/course/report/participation/index.php +++ b/course/report/participation/index.php @@ -189,21 +189,20 @@ } list($actionsql, $params) = $DB->get_in_or_equal($actions, SQL_PARAMS_NAMED, 'action0'); - $actionsql = "l.action $actionsql"; + $actionsql = "action $actionsql"; $relatedcontexts = get_related_contexts_string($context); $sql = "SELECT ra.userid, u.firstname, u.lastname, u.idnumber, COUNT(l.action) AS count - FROM {role_assignments} ra + FROM (SELECT * FROM {role_assignments} WHERE contextid $relatedcontexts AND roleid = :roleid) ra JOIN {user} u ON u.id = ra.userid - LEFT JOIN {log} l ON (l.userid = ra.userid AND l.cmid = :instanceid AND l.time > :timefrom AND $actionsql) - WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid"; + LEFT JOIN (SELECT * FROM {log} WHERE cmid = :instanceid AND time > :timefrom AND $actionsql) l ON (l.userid = ra.userid)"; $params['roleid'] = $roleid; $params['instanceid'] = $instanceid; $params['timefrom'] = $timefrom; if ($table->get_sql_where()) { - $sql .= ' AND '.$table->get_sql_where(); //initial bar + $sql .= ' WHERE '.$table->get_sql_where(); //initial bar } $sql .= " GROUP BY ra.userid, u.firstname, u.lastname, u.idnumber"; @@ -213,15 +212,13 @@ } $countsql = "SELECT COUNT(DISTINCT(ra.userid)) - FROM {role_assignments} ra - JOIN {user} u ON u.id = ra.userid - LEFT OUTER JOIN {log} l ON (l.userid = ra.userid AND l.cmid = :instanceid AND l.time > :timefrom AND $actionsql) - WHERE ra.contextid $relatedcontexts AND ra.roleid = :roleid"; + FROM (SELECT * FROM {role_assignments} WHERE contextid $relatedcontexts AND roleid = :roleid) ra + JOIN {user} u ON u.id = ra.userid"; $totalcount = $DB->count_records_sql($countsql, $params); if ($table->get_sql_where()) { - $matchcount = $DB->count_records_sql($countsql.' AND '.$table->get_sql_where(), $params); + $matchcount = $DB->count_records_sql($countsql.' WHERE '.$table->get_sql_where(), $params); } else { $matchcount = $totalcount; } -- 1.7.0.2.msysgit.0