Commit 0c2ddb68 authored by Mark Nielsen's avatar Mark Nielsen Committed by Dan Poltawski
Browse files

MDL-51498 core_grades: Prevent unnecessary grade record fetching

All of these changes make use of already
fetched grade data.  Without these changes,
the gradebook regrade process does not scale
well with very large courses because it fetches
many grade records, one at a time.
parent 8ae33bc9
......@@ -466,7 +466,7 @@ class grade_category extends grade_object {
WHERE id $usql";
$items = $DB->get_records_sql($sql, $params);
foreach ($items as $id => $item) {
$items[$id] = new grade_item($item);
$items[$id] = new grade_item($item, false);
}
}
......@@ -501,10 +501,13 @@ class grade_category extends grade_object {
$grademinoverrides = array();
foreach ($rs as $used) {
$grade = new grade_grade($used);
$grade = new grade_grade($used, false);
if (isset($items[$grade->itemid])) {
// Prevent grade item to be fetched from DB.
$grade->grade_item =& $items[$grade->itemid];
} else if ($grade->itemid == $this->grade_item->id) {
// This grade's grade item is not in $items.
$grade->grade_item =& $this->grade_item;
}
if ($grade->userid != $prevuser) {
$this->aggregate_grades($prevuser,
......@@ -882,7 +885,7 @@ class grade_category extends grade_object {
& $weights = null,
$grademinoverrides = array(),
$grademaxoverrides = array()) {
$category_item = $this->get_grade_item();
$category_item = $this->load_grade_item();
$grademin = $category_item->grademin;
$grademax = $category_item->grademax;
......
......@@ -680,7 +680,7 @@ class grade_item extends grade_object {
// aggregate the category grade
} else if ($this->is_category_item() or $this->is_course_item()) {
// aggregate category grade item
$category = $this->get_item_category();
$category = $this->load_item_category();
$category->grade_item =& $this;
if ($category->generate_grades($userid)) {
return true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment