mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-32659 potential navigation course loading improvements
The idea is to not use inequalities in SQL queries for loading of courses in navigation because ti seems some SQL query optimiser have problems with that.
This commit is contained in:
parent
71d7bc34a8
commit
fca2d3d754
@ -1577,21 +1577,29 @@ class global_navigation extends navigation_node {
|
|||||||
// First up fetch all of the courses in categories where we know that we are going to
|
// First up fetch all of the courses in categories where we know that we are going to
|
||||||
// need the majority of courses.
|
// need the majority of courses.
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
||||||
list($courseids, $courseparams) = $DB->get_in_or_equal(array_keys($this->addedcourses) + array($SITE->id), SQL_PARAMS_NAMED, 'lcourse', false);
|
|
||||||
list($categoryids, $categoryparams) = $DB->get_in_or_equal($fullfetch, SQL_PARAMS_NAMED, 'lcategory');
|
list($categoryids, $categoryparams) = $DB->get_in_or_equal($fullfetch, SQL_PARAMS_NAMED, 'lcategory');
|
||||||
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
$ccjoin
|
$ccjoin
|
||||||
WHERE c.category {$categoryids} AND
|
WHERE c.category {$categoryids}
|
||||||
c.id {$courseids}
|
|
||||||
ORDER BY c.sortorder ASC";
|
ORDER BY c.sortorder ASC";
|
||||||
$coursesrs = $DB->get_recordset_sql($sql, $courseparams + $categoryparams);
|
$coursesrs = $DB->get_recordset_sql($sql, $categoryparams);
|
||||||
foreach ($coursesrs as $course) {
|
foreach ($coursesrs as $course) {
|
||||||
|
if ($course->id == $SITE->id) {
|
||||||
|
// This should not be necessary, frontpage is not in any category.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (array_key_exists($course->id, $this->addedcourses)) {
|
||||||
|
// It is probably better to not include the already loaded courses
|
||||||
|
// directly in SQL because inequalities may confuse query optimisers
|
||||||
|
// and may interfere with query caching.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!$this->can_add_more_courses_to_category($course->category)) {
|
if (!$this->can_add_more_courses_to_category($course->category)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
context_instance_preload($course);
|
context_instance_preload($course);
|
||||||
if ($course->id != $SITE->id && !$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$coursenodes[$course->id] = $this->add_course($course);
|
$coursenodes[$course->id] = $this->add_course($course);
|
||||||
@ -1604,21 +1612,30 @@ class global_navigation extends navigation_node {
|
|||||||
// proportion of the courses.
|
// proportion of the courses.
|
||||||
foreach ($partfetch as $categoryid) {
|
foreach ($partfetch as $categoryid) {
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
||||||
list($courseids, $courseparams) = $DB->get_in_or_equal(array_keys($this->addedcourses) + array($SITE->id), SQL_PARAMS_NAMED, 'lcourse', false);
|
|
||||||
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
$ccjoin
|
$ccjoin
|
||||||
WHERE c.category = :categoryid AND
|
WHERE c.category = :categoryid
|
||||||
c.id {$courseids}
|
|
||||||
ORDER BY c.sortorder ASC";
|
ORDER BY c.sortorder ASC";
|
||||||
$courseparams['categoryid'] = $categoryid;
|
$courseparams = array('categoryid' => $categoryid);
|
||||||
$coursesrs = $DB->get_recordset_sql($sql, $courseparams, 0, $limit * 5);
|
$coursesrs = $DB->get_recordset_sql($sql, $courseparams, 0, $limit * 5);
|
||||||
foreach ($coursesrs as $course) {
|
foreach ($coursesrs as $course) {
|
||||||
|
if ($course->id == $SITE->id) {
|
||||||
|
// This should not be necessary, frontpage is not in any category.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (array_key_exists($course->id, $this->addedcourses)) {
|
||||||
|
// It is probably better to not include the already loaded courses
|
||||||
|
// directly in SQL because inequalities may confuse query optimisers
|
||||||
|
// and may interfere with query caching.
|
||||||
|
// This also helps to respect expected $limit on repeated executions.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!$this->can_add_more_courses_to_category($course->category)) {
|
if (!$this->can_add_more_courses_to_category($course->category)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
context_instance_preload($course);
|
context_instance_preload($course);
|
||||||
if ($course->id != $SITE->id && !$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$coursenodes[$course->id] = $this->add_course($course);
|
$coursenodes[$course->id] = $this->add_course($course);
|
||||||
@ -1637,8 +1654,12 @@ class global_navigation extends navigation_node {
|
|||||||
ORDER BY c.sortorder ASC";
|
ORDER BY c.sortorder ASC";
|
||||||
$coursesrs = $DB->get_recordset_sql($sql, $courseparams);
|
$coursesrs = $DB->get_recordset_sql($sql, $courseparams);
|
||||||
foreach ($coursesrs as $course) {
|
foreach ($coursesrs as $course) {
|
||||||
|
if ($course->id == $SITE->id) {
|
||||||
|
// frotpage is not wanted here
|
||||||
|
continue;
|
||||||
|
}
|
||||||
context_instance_preload($course);
|
context_instance_preload($course);
|
||||||
if ($course->id != $SITE->id && !$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$coursenodes[$course->id] = $this->add_course($course);
|
$coursenodes[$course->id] = $this->add_course($course);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user