From aac8dfa8b65adfba84cdf04f29f060eaeb048d63 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Thu, 6 Nov 2014 14:03:38 +1300 Subject: [PATCH] MDL-48070 navigation: optimised the login page The navigation and settings no longer get initialised on the login page by default, this is achieved by calling to ignore the active page on the navbar. It is safe because the login page is not represented in either the navigation or the settings. This change saves a few MB or ram and a couple of database queries --- lib/navigationlib.php | 19 ++++++++++--------- login/index.php | 4 ++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index cd8d996096a..eb6661fae2c 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -3088,12 +3088,14 @@ class navbar extends navigation_node { } else if ($this->hasitems !== false) { return true; } - $this->page->navigation->initialise($this->page); - - $activenodefound = ($this->page->navigation->contains_active_node() || - $this->page->settingsnav->contains_active_node()); - - $outcome = (count($this->children) > 0 || count($this->prependchildren) || (!$this->ignoreactive && $activenodefound)); + if (count($this->children) > 0 || count($this->prependchildren) > 0) { + // There have been manually added items - there are definitely items. + $outcome = true; + } else if (!$this->ignoreactive) { + // We will need to initialise the navigation structure to check if there are active items. + $this->page->navigation->initialise($this->page); + $outcome = ($this->page->navigation->contains_active_node() || $this->page->settingsnav->contains_active_node()); + } $this->hasitems = $outcome; return $outcome; } @@ -3148,11 +3150,10 @@ class navbar extends navigation_node { $items = array_reverse($this->children); } - $navigationactivenode = $this->page->navigation->find_active_node(); - $settingsactivenode = $this->page->settingsnav->find_active_node(); - // Check if navigation contains the active node if (!$this->ignoreactive) { + $navigationactivenode = $this->page->navigation->find_active_node(); + $settingsactivenode = $this->page->settingsnav->find_active_node(); if ($navigationactivenode && $settingsactivenode) { // Parse a combined navigation tree diff --git a/login/index.php b/login/index.php index 587eb0efec4..ab2b802f153 100644 --- a/login/index.php +++ b/login/index.php @@ -93,6 +93,10 @@ foreach($authsequence as $authname) { /// Define variables used in page $site = get_site(); +// Ignore any active pages in the navigation/settings. +// We do this because there won't be an active page there, and by ignoring the active pages the +// navigation and settings won't be initialised unless something else needs them. +$PAGE->navbar->ignore_active(); $loginsite = get_string("loginsite"); $PAGE->navbar->add($loginsite);