1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-17 22:45:54 +02:00

MDL-65393 core: Peer review amendments

- defining and using constand properties instead of hard-coded values
- Fixing the docblock for the cleanup_recent_session_locks function
This commit is contained in:
Shamim Rezaie 2019-05-15 02:30:48 +10:00
parent dbed8bdb86
commit abbf6e5499

@ -42,6 +42,12 @@ use html_writer;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manager {
/** @var int A hard cutoff of maximum stored history */
const MAXIMUM_STORED_SESSION_HISTORY = 50;
/** @var int The recent session locks array is reset if there is a time gap more than this value in seconds */
const SESSION_RESET_GAP_THRESHOLD = 1;
/** @var handler $handler active session handler instance */
protected static $handler;
@ -1101,25 +1107,23 @@ class manager {
}
/**
* Reset recent session locks array if there is a 10 seconds time gap.
*
* @return array Recent session locks array.
* Reset recent session locks array if there is a time gap more than SESSION_RESET_GAP_THRESHOLD.
*/
public static function cleanup_recent_session_locks() {
global $SESSION;
$locks = self::get_recent_session_locks();
$maximumstoredhistory = 50;
if (count($locks) > $maximumstoredhistory) {
$locks = array_slice($locks, -$maximumstoredhistory);
if (count($locks) > self::MAXIMUM_STORED_SESSION_HISTORY) {
// Keep the last MAXIMUM_STORED_SESSION_HISTORY locks and ignore the rest.
$locks = array_slice($locks, -1 * self::MAXIMUM_STORED_SESSION_HISTORY);
}
if (count($locks) > 2) {
for ($i = count($locks) - 1; $i > 0; $i--) {
// Calculate the gap between session locks.
$gap = $locks[$i]['released'] - $locks[$i - 1]['start'];
if ($gap >= 1) {
if ($gap >= self::SESSION_RESET_GAP_THRESHOLD) {
// Remove previous locks if the gap is 1 second or more.
$SESSION->recentsessionlocks = array_slice($locks, $i);
break;