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.
This commit is contained in:
Mark Nielsen 2015-09-22 12:04:28 -07:00
parent d230899db8
commit 5f6e2fc9d3
2 changed files with 7 additions and 4 deletions

View File

@ -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;

View File

@ -694,7 +694,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;