From 82da35fd516c72e9b1ed0779051babab1faaa7e2 Mon Sep 17 00:00:00 2001 From: Adam Eijdenberg Date: Tue, 28 Feb 2017 13:21:58 +1100 Subject: [PATCH] MDL-58018 core: Enable read-only sessions for key pages These pages are often loaded in parallel. --- lib/ajax/getnavbranch.php | 1 + lib/ajax/service.php | 2 ++ lib/db/services.php | 2 ++ lib/externallib.php | 10 ++++++++++ message/output/popup/db/services.php | 1 + pluginfile.php | 1 + 6 files changed, 17 insertions(+) diff --git a/lib/ajax/getnavbranch.php b/lib/ajax/getnavbranch.php index 17b2668d5ca..76db3f42fe8 100644 --- a/lib/ajax/getnavbranch.php +++ b/lib/ajax/getnavbranch.php @@ -26,6 +26,7 @@ */ define('AJAX_SCRIPT', true); +define('REQUIRE_SESSION_LOCK', false); /** Include config */ require_once(__DIR__ . '/../../config.php'); diff --git a/lib/ajax/service.php b/lib/ajax/service.php index 3bcb8e9621e..098f806ec5e 100644 --- a/lib/ajax/service.php +++ b/lib/ajax/service.php @@ -28,6 +28,8 @@ */ define('AJAX_SCRIPT', true); +// Services can declare 'requiresessionlock' in their config located in db/services.php, if not present will default to true. +define('REQUIRE_SESSION_LOCK', false); if (!empty($_GET['nosessionupdate'])) { define('NO_SESSION_UPDATE', true); diff --git a/lib/db/services.php b/lib/db/services.php index a9c81066c08..1e96a514211 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -748,6 +748,7 @@ $functions = array( 'type' => 'read', 'loginrequired' => false, 'ajax' => true, + 'requiresessionlock' => true, // Fetching removes from stack. ), 'core_session_touch' => array( 'classname' => 'core\session\external', @@ -1374,6 +1375,7 @@ $functions = array( 'type' => 'read', 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), + 'requiresessionlock' => false, // We don't modify the session. ), 'core_message_mark_all_notifications_as_read' => array( 'classname' => 'core_message_external', diff --git a/lib/externallib.php b/lib/externallib.php index 24002e0bc44..4cb626b7996 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -161,6 +161,11 @@ class external_api { } else { $function->loginrequired = true; } + if (isset($functions[$function->name]['requiresessionlock'])) { + $function->requiresessionlock = $functions[$function->name]['requiresessionlock']; + } else { + $function->requiresessionlock = true; + } } return $function; @@ -184,6 +189,11 @@ class external_api { $externalfunctioninfo = static::external_function_info($function); + // Eventually this should shift into the various handlers and not be handled via config. + if ($externalfunctioninfo->requiresessionlock) { + \core\session\manager::restart_with_write_lock(); + } + $currentpage = $PAGE; $currentcourse = $COURSE; $response = array(); diff --git a/message/output/popup/db/services.php b/message/output/popup/db/services.php index 89809e4115c..f7a5d833f57 100644 --- a/message/output/popup/db/services.php +++ b/message/output/popup/db/services.php @@ -41,5 +41,6 @@ $functions = array( 'type' => 'read', 'ajax' => true, 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), + 'requiresessionlock' => false, ), ); diff --git a/pluginfile.php b/pluginfile.php index 24e6cda10e9..76742f9ee50 100644 --- a/pluginfile.php +++ b/pluginfile.php @@ -28,6 +28,7 @@ if (!defined('NO_DEBUG_DISPLAY')) { define('NO_DEBUG_DISPLAY', true); } +define('REQUIRE_SESSION_LOCK', false); // Plugins will need to acquire a lock if they need one. require_once('config.php'); require_once('lib/filelib.php');