mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-82605 contentbank: pre-load contexts for options list.
Prevents additional DB reads per category/course, which can be potentially expensive on large sites.
This commit is contained in:
parent
e0381615aa
commit
09fae09cd5
@ -14,14 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Content bank class
|
||||
*
|
||||
* @package core_contentbank
|
||||
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_contentbank;
|
||||
|
||||
use core_plugin_manager;
|
||||
@ -246,8 +238,11 @@ class contentbank {
|
||||
$courses = $coursescache->get($userid);
|
||||
|
||||
if ($categories === false || $courses === false) {
|
||||
// Required fields for preloading the context record.
|
||||
$contextfields = 'ctxid, ctxpath, ctxdepth, ctxlevel, ctxinstance, ctxlocked';
|
||||
|
||||
list($categories, $courses) = get_user_capability_contexts($capability, true, $userid, true,
|
||||
'fullname, ctxlevel, ctxinstance, ctxid', 'name, ctxlevel, ctxinstance, ctxid', 'fullname', 'name');
|
||||
"fullname, {$contextfields}", "name, {$contextfields}", 'fullname', 'name');
|
||||
$categoriescache->set($userid, $categories);
|
||||
$coursescache->set($userid, $courses);
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
namespace core_contentbank\output;
|
||||
|
||||
use context_course;
|
||||
use context_coursecat;
|
||||
use core\context\{course, coursecat};
|
||||
use core\context_helper;
|
||||
use core_contentbank\content;
|
||||
use core_contentbank\contentbank;
|
||||
use renderable;
|
||||
@ -133,8 +133,9 @@ class bankcontent implements renderable, templatable {
|
||||
}
|
||||
$options = [];
|
||||
foreach ($this->allowedcategories as $allowedcategory) {
|
||||
context_helper::preload_from_record(clone $allowedcategory);
|
||||
$options[$allowedcategory->ctxid] = format_string($allowedcategory->name, true, [
|
||||
'context' => context_coursecat::instance($allowedcategory->ctxinstance),
|
||||
'context' => coursecat::instance($allowedcategory->ctxinstance),
|
||||
]);
|
||||
}
|
||||
if (!empty($options)) {
|
||||
@ -144,8 +145,9 @@ class bankcontent implements renderable, templatable {
|
||||
foreach ($this->allowedcourses as $allowedcourse) {
|
||||
// Don't add the frontpage course to the list.
|
||||
if ($allowedcourse->id != $SITE->id) {
|
||||
context_helper::preload_from_record(clone $allowedcourse);
|
||||
$options[$allowedcourse->ctxid] = format_string($allowedcourse->fullname, true, [
|
||||
'context' => context_course::instance($allowedcourse->ctxinstance),
|
||||
'context' => course::instance($allowedcourse->ctxinstance),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user