Skip to content

Commit

Permalink
MDL-51498 core_grades: Prevent unnecessary grade record fetching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
polothy committed Sep 22, 2015
1 parent d230899 commit 5f6e2fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/grade/grade_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public function generate_grades($userid=null) {
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);
}
}

Expand Down Expand Up @@ -501,10 +501,13 @@ public function generate_grades($userid=null) {
$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,
Expand Down Expand Up @@ -882,7 +885,7 @@ public function aggregate_values_and_adjust_bounds($grade_values,
& $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;

Expand Down
2 changes: 1 addition & 1 deletion lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ public function regrade_final_grades($userid=null) {
// 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;
Expand Down

0 comments on commit 5f6e2fc

Please sign in to comment.