Skip to content

Commit

Permalink
MDL-66075 mod_forum: reduce DB reads in forum settings generation
Browse files Browse the repository at this point in the history
Instead of fetching the DB record AND then fetching it again (as
part of the vault->get_from_id() call, just use the legacy data
mapper and remove the DB call.
  • Loading branch information
snake committed Sep 27, 2019
1 parent c3122df commit f5e6bcf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5235,15 +5235,16 @@ function forum_get_extra_capabilities() {
function forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode) {
global $USER, $PAGE, $CFG, $DB, $OUTPUT;

$forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance));
if (empty($PAGE->cm->context)) {
$PAGE->cm->context = context_module::instance($PAGE->cm->instance);
}

$vaultfactory = mod_forum\local\container::get_vault_factory();
$managerfactory = mod_forum\local\container::get_manager_factory();
$legacydatamapperfactory = mod_forum\local\container::get_legacy_data_mapper_factory();
$forumvault = $vaultfactory->get_forum_vault();
$forumentity = $forumvault->get_from_id($forumobject->id);
$forumentity = $forumvault->get_from_id($PAGE->cm->instance);
$forumobject = $legacydatamapperfactory->get_forum_data_mapper()->to_legacy_object($forumentity);

$params = $PAGE->url->params();
if (!empty($params['d'])) {
Expand Down

0 comments on commit f5e6bcf

Please sign in to comment.