Merge branch 'MDL-71899-311-2' of git://github.com/HuongNV13/moodle into MOODLE_311_STABLE
This commit is contained in:
@@ -65,7 +65,9 @@ class cm_completion_details {
|
||||
*/
|
||||
public function __construct(completion_info $completioninfo, cm_info $cminfo, int $userid, bool $returndetails = true) {
|
||||
$this->completioninfo = $completioninfo;
|
||||
$this->completiondata = $completioninfo->get_data($cminfo, false, $userid);
|
||||
// We need to pass wholecourse = true here for better performance. All the course's completion data for the current
|
||||
// logged-in user will get in a single query instead of multiple queries and loaded to cache.
|
||||
$this->completiondata = $completioninfo->get_data($cminfo, true, $userid);
|
||||
$this->cminfo = $cminfo;
|
||||
$this->userid = $userid;
|
||||
$this->returndetails = $returndetails;
|
||||
|
||||
+2
-1
@@ -56,7 +56,8 @@ class course_image implements cache_data_source {
|
||||
* @return string|bool Returns course image url as a string or false if the image is not exist
|
||||
*/
|
||||
public function load_for_cache($key) {
|
||||
$course = get_fast_modinfo($key)->get_course();
|
||||
// We should use get_course() instead of get_fast_modinfo() for better performance.
|
||||
$course = get_course($key);
|
||||
return $this->get_image_url_from_overview_files($course);
|
||||
}
|
||||
|
||||
|
||||
+17
-27
@@ -1055,39 +1055,29 @@ class completion_info {
|
||||
// Fetch completion data for all of the activities in the course ONLY if we're caching the fetched completion data.
|
||||
// If we're not caching the completion data, then just fetch the completion data for the user in this course module.
|
||||
if ($usecache && $wholecourse) {
|
||||
// Get whole course data for cache
|
||||
$alldatabycmc = $DB->get_records_sql("
|
||||
SELECT
|
||||
cmc.*
|
||||
FROM
|
||||
{course_modules} cm
|
||||
INNER JOIN {course_modules_completion} cmc ON cmc.coursemoduleid=cm.id
|
||||
WHERE
|
||||
cm.course=? AND cmc.userid=?", array($this->course->id, $userid));
|
||||
// Get whole course data for cache.
|
||||
$alldatabycmc = $DB->get_records_sql("SELECT cm.id AS cmid, cmc.*
|
||||
FROM {course_modules} cm
|
||||
LEFT JOIN {course_modules_completion} cmc ON cmc.coursemoduleid = cm.id
|
||||
AND cmc.userid = ?
|
||||
INNER JOIN {modules} m ON m.id = cm.module
|
||||
WHERE m.visible = 1 AND cm.course = ?", [$userid, $this->course->id]);
|
||||
|
||||
// Reindex by cm id
|
||||
$alldata = array();
|
||||
// Reindex by course module id.
|
||||
foreach ($alldatabycmc as $data) {
|
||||
$alldata[$data->coursemoduleid] = (array)$data;
|
||||
}
|
||||
|
||||
// Get the module info and build up condition info for each one
|
||||
if (empty($modinfo)) {
|
||||
$modinfo = get_fast_modinfo($this->course, $userid);
|
||||
}
|
||||
foreach ($modinfo->cms as $othercm) {
|
||||
if (isset($alldata[$othercm->id])) {
|
||||
$data = $alldata[$othercm->id];
|
||||
if (empty($data->coursemoduleid)) {
|
||||
$cacheddata[$data->cmid] = $defaultdata;
|
||||
$cacheddata[$data->cmid]['coursemoduleid'] = $data->cmid;
|
||||
} else {
|
||||
// Row not present counts as 'not complete'.
|
||||
$data = $defaultdata;
|
||||
$data['coursemoduleid'] = $othercm->id;
|
||||
$cacheddata[$data->cmid] = (array) $data;
|
||||
}
|
||||
// Make sure we're working on a cm_info object.
|
||||
$othercminfo = cm_info::create($othercm, $userid);
|
||||
$cmstd = new stdClass();
|
||||
$cmstd->id = $data->cmid;
|
||||
$cmstd->course = $this->course->id;
|
||||
$othercminfo = cm_info::create($cmstd, $userid);
|
||||
// Add the other completion data for this user in this module instance.
|
||||
$data += $this->get_other_cm_completion_data($othercminfo, $userid);
|
||||
$cacheddata[$othercminfo->id] = $data;
|
||||
$cacheddata[$othercminfo->id] += $this->get_other_cm_completion_data($othercminfo, $userid);
|
||||
}
|
||||
|
||||
if (!isset($cacheddata[$cminfo->id])) {
|
||||
|
||||
Reference in New Issue
Block a user