mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-42020 course: performance improvement in course listings
- better performance when get_course_count() OR search_course_count() are called by themselves - better performance in displaying course contacts
This commit is contained in:
parent
56cc9b387e
commit
bf1405a60a
@ -1108,6 +1108,15 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
if (!empty($ids)) {
|
||||
list($sql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'id');
|
||||
$records = self::get_course_records("c.id ". $sql, $params, $options);
|
||||
// Preload course contacts if necessary - saves DB queries later to do it for each course separately.
|
||||
if (!empty($options['coursecontacts'])) {
|
||||
self::preload_course_contacts($records);
|
||||
}
|
||||
// If option 'idonly' is specified no further action is needed, just return list of ids.
|
||||
if (!empty($options['idonly'])) {
|
||||
return array_keys($records);
|
||||
}
|
||||
// Prepare the list of course_in_list objects.
|
||||
foreach ($ids as $id) {
|
||||
$courses[$id] = new course_in_list($records[$id]);
|
||||
}
|
||||
@ -1159,6 +1168,11 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
if (!empty($preloadcoursecontacts)) {
|
||||
self::preload_course_contacts($records);
|
||||
}
|
||||
// If option 'idonly' is specified no further action is needed, just return list of ids.
|
||||
if (!empty($options['idonly'])) {
|
||||
return array_keys($records);
|
||||
}
|
||||
// Prepare the list of course_in_list objects.
|
||||
$courses = array();
|
||||
foreach ($records as $record) {
|
||||
$courses[$record->id] = new course_in_list($record);
|
||||
@ -1187,6 +1201,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
unset($options['limit']);
|
||||
unset($options['summary']);
|
||||
unset($options['coursecontacts']);
|
||||
$options['idonly'] = true;
|
||||
$courses = self::search_courses($search, $options);
|
||||
$cnt = count($courses);
|
||||
}
|
||||
@ -1226,6 +1241,8 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
* Only cached fields may be used for sorting!
|
||||
* - offset
|
||||
* - limit - maximum number of children to return, 0 or null for no limit
|
||||
* - idonly - returns the array or course ids instead of array of objects
|
||||
* used only in get_courses_count()
|
||||
* @return course_in_list[]
|
||||
*/
|
||||
public function get_courses($options = array()) {
|
||||
@ -1255,6 +1272,15 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
if (!empty($ids)) {
|
||||
list($sql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'id');
|
||||
$records = self::get_course_records("c.id ". $sql, $params, $options);
|
||||
// Preload course contacts if necessary - saves DB queries later to do it for each course separately.
|
||||
if (!empty($options['coursecontacts'])) {
|
||||
self::preload_course_contacts($records);
|
||||
}
|
||||
// If option 'idonly' is specified no further action is needed, just return list of ids.
|
||||
if (!empty($options['idonly'])) {
|
||||
return array_keys($records);
|
||||
}
|
||||
// Prepare the list of course_in_list objects.
|
||||
foreach ($ids as $id) {
|
||||
$courses[$id] = new course_in_list($records[$id]);
|
||||
}
|
||||
@ -1293,6 +1319,11 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
if (!empty($options['coursecontacts'])) {
|
||||
self::preload_course_contacts($list);
|
||||
}
|
||||
// If option 'idonly' is specified no further action is needed, just return list of ids.
|
||||
if (!empty($options['idonly'])) {
|
||||
return array_keys($list);
|
||||
}
|
||||
// Prepare the list of course_in_list objects.
|
||||
foreach ($list as $record) {
|
||||
$courses[$record->id] = new course_in_list($record);
|
||||
}
|
||||
@ -1316,6 +1347,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
unset($options['limit']);
|
||||
unset($options['summary']);
|
||||
unset($options['coursecontacts']);
|
||||
$options['idonly'] = true;
|
||||
$courses = $this->get_courses($options);
|
||||
$cnt = count($courses);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user