Moodle 2 Slow Admin login

Re: Moodle 2 Slow Admin login

by Valery Fremaux -
Number of replies: 0
Picture of Plugin developers

Master reason of this slowness comes essentially from the site admin construction and from settings.php and version.php check for upgrades and pulling out all settings. 

I noticed that the more plugins you add into moodle, the slower is this admin construction. 

My solution was to create a "admin_light" block which will replace on home page the site administration part of the menu of the standard "settings".

Unfortunately, for this working, i had to patch a core library : navigationlib.php to trap this admin menu generation part. This redraws the function "initialize()" of the navigation like this : 

public function initialise() {
global $DB, $SESSION, $SITE;
   if (during_initial_install()) {
return false;
} else if ($this->initialised) {
return true;
}
$this->id = 'settingsnav';
$this->context = $this->page->context;
  $context = $this->context;
if ($context->contextlevel == CONTEXT_BLOCK) {
$this->load_block_settings();
$context = $context->get_parent_context();
}
 switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
if ($this->page->url->compare(new moodle_url('/admin/settings.php', array('section'=>'frontpagesettings')))) {
$this->load_front_page_settings(($context->id == $this->context->id));
}
break;
case CONTEXT_COURSECAT:
$this->load_category_settings();
break;
case CONTEXT_COURSE:
if ($this->page->course->id != $SITE->id) {
$this->load_course_settings(($context->id == $this->context->id));
} else {
$this->load_front_page_settings(($context->id == $this->context->id));
}
break;
case CONTEXT_MODULE:
$this->load_module_settings();
$this->load_course_settings();
break;
case CONTEXT_USER:
if ($this->page->course->id != $SITE->id) {
$this->load_course_settings();
}
break;
}
 $settings = $this->load_user_settings($this->page->course->id);
// PATCH : enable admin administration in admin pages only
global $PAGE;
if (isloggedin() && !isguestuser() && (!property_exists($SESSION, 'load_navigation_admin') || $SESSION->load_navigation_admin) && (preg_match('/admin/', $PAGE->pagetype) || !empty($SESSION->adminlocked))) {
$admin = $this->load_administration_settings();
$SESSION->load_navigation_admin = ($admin->has_children());
} else {
$admin = false;
}
// /PATCH
if ($context->contextlevel == CONTEXT_SYSTEM && $admin) {
$admin->force_open();
} else if ($context->contextlevel == CONTEXT_USER && $settings) {
$settings->force_open();
}
  // Check if the user is currently logged in as another user
if (session_is_loggedinas()) {
// Get the actual user, we need this so we can display an informative return link
$realuser = session_get_realuser();
// Add the informative return to original user link
$url = new moodle_url('/course/loginas.php',array('id'=>$this->page->course->id, 'return'=>1,'sesskey'=>sesskey()));
$this->add(get_string('returntooriginaluser', 'moodle', fullname($realuser, true)), $url, self::TYPE_SETTING, null, null, new pix_icon('t/left', ''));
}
 // At this point we give any local plugins the ability to extend/tinker with the navigation settings.
$this->load_local_plugin_settings();
 foreach ($this->children as $key=>$node) {
if ($node->nodetype != self::NODETYPE_BRANCH || $node->children->count()===0) {
$node->remove();
}
}
$this->initialised = true;
}

The effect of this is : 

Allows site admin menu to load in all administration pages.

Provides choice NOT to load it on common pages, unless you force loading in session for a while. Then the admin_light block gives you a link to go to an admin page to find your site admin menu back.

This improves a loooot the loading time of the index and common pages for administrators when you combine a strongly contributed moodle version + a medium size or small size server.

Note that this trick suits essentially to 2.4 and 2.5 versions, as 2.6 version have Ajaxed the administration site menu, thus defferring those long searches to an explicit query.

Of course, woking with fast hard drives (SSD local drives) will be a "hard technical" alternative solution also...

Valery.