Commit 9813cbb9 authored by Robert Lyon's avatar Robert Lyon

Reducing the number of calls to Mobile_Detect->isMobile() (Bug #1427031)

We seem to be calling it on every page load - so for a page with lots
of blocks it means a lot of calls.

When really we should call it once when a user first arrives as they
won't be switching devices during their session.

Change-Id: Id939ad83c5acfdbcdd358691def25bd2e5f5a592
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent a1eeb3ea
......@@ -453,19 +453,24 @@ if (defined('JSON') && !defined('NOSESSKEY')) {
json_reply('global', get_string('invalidsesskey'), 1);
}
}
$mobile_detection_done = $SESSION->get('mobile_detection');
// Device detection
if (get_config('installed') && get_account_preference($USER->get('id'), 'devicedetection')) {
require_once(get_config('libroot') . 'mobile_detect/Mobile_Detect.php');
$detect = new Mobile_Detect();
$SESSION->set('handheld_device', $detect->isMobile());
$SESSION->set('mobile', $detect->isTablet() ? false : $detect->isMobile());
$SESSION->set('tablet', $detect->isTablet());
}
else {
$SESSION->set('handheld_device', false);
$SESSION->set('mobile', false);
$SESSION->set('tablet', false);
if (!$mobile_detection_done) {
if (get_config('installed') && get_account_preference($USER->get('id'), 'devicedetection')) {
require_once(get_config('libroot') . 'mobile_detect/Mobile_Detect.php');
$detect = new Mobile_Detect();
$isMobile = $detect->isMobile();
$isTablet = $detect->isTablet();
$SESSION->set('handheld_device', $isMobile);
$SESSION->set('mobile', $isTablet ? false : $isMobile);
$SESSION->set('tablet', $isTablet);
}
else {
$SESSION->set('handheld_device', false);
$SESSION->set('mobile', false);
$SESSION->set('tablet', false);
}
$SESSION->set('mobile_detection', true);
}
// Run modules bootstrap code.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment