public static function cleanup_recent_session_locks() {
        global $SESSION;

        $locks = self::get_recent_session_locks();
        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 >= 10) {
                    // Remove previous locks if the gap is 10 seconds or more.
                    $SESSION->recentsessionlocks = array_slice($locks, $i);
                    break;
                }
            }
        }
    }