mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-51514 gradebook: Optimize set_usedinaggregation query for MySQL
This commit is contained in:
parent
35d3e8b00b
commit
84ab39cf77
@ -793,15 +793,28 @@ class grade_category extends grade_object {
|
||||
|
||||
// Reset aggregation to unknown and 0 for all grade items for this user and category.
|
||||
$params = array('categoryid' => $this->id, 'userid' => $userid);
|
||||
$itemssql = "SELECT id
|
||||
FROM {grade_items}
|
||||
WHERE categoryid = :categoryid";
|
||||
|
||||
$sql = "UPDATE {grade_grades}
|
||||
SET aggregationstatus = 'unknown',
|
||||
aggregationweight = 0
|
||||
WHERE userid = :userid
|
||||
AND itemid IN ($itemssql)";
|
||||
switch ($DB->get_dbfamily()) {
|
||||
case 'mysql':
|
||||
// Optimize the query for MySQL by using a join rather than a sub-query.
|
||||
$sql = "UPDATE {grade_grades} g
|
||||
JOIN {grade_items} gi ON (g.itemid = gi.id)
|
||||
SET g.aggregationstatus = 'unknown',
|
||||
g.aggregationweight = 0
|
||||
WHERE g.userid = :userid
|
||||
AND gi.categoryid = :categoryid";
|
||||
break;
|
||||
default:
|
||||
$itemssql = "SELECT id
|
||||
FROM {grade_items}
|
||||
WHERE categoryid = :categoryid";
|
||||
|
||||
$sql = "UPDATE {grade_grades}
|
||||
SET aggregationstatus = 'unknown',
|
||||
aggregationweight = 0
|
||||
WHERE userid = :userid
|
||||
AND itemid IN ($itemssql)";
|
||||
}
|
||||
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user