diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-04-26 12:57:58 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-08-17 12:10:26 +0200 |
commit | 9b4b72826ade5ab1bc7fb06048e62910ef607cd8 (patch) | |
tree | ef8d14e06608c0491361eb9d2666f8523647272e /lib/private/Session/CryptoSessionData.php | |
parent | 312b719acf686f51065e83290cd88704d703a50c (diff) | |
download | nextcloud-server-9b4b72826ade5ab1bc7fb06048e62910ef607cd8.tar.gz nextcloud-server-9b4b72826ade5ab1bc7fb06048e62910ef607cd8.zip |
Reopen sessions if we need to write to them instead of keeping them open
Sessions are a locking operation until we write close them, so close
them early and reopen later in case we want to write to them
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/Session/CryptoSessionData.php')
-rw-r--r-- | lib/private/Session/CryptoSessionData.php | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php index 2e3bd46da5b..b01887e39e2 100644 --- a/lib/private/Session/CryptoSessionData.php +++ b/lib/private/Session/CryptoSessionData.php @@ -97,8 +97,17 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param mixed $value */ public function set(string $key, $value) { + if ($this->get($key) === $value) { + // Do not write the session if the value hasn't changed to avoid reopening + return; + } + + $reopened = $this->reopen(); $this->sessionValues[$key] = $value; $this->isModified = true; + if ($reopened) { + $this->close(); + } } /** @@ -131,9 +140,13 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param string $key */ public function remove(string $key) { + $reopened = $this->reopen(); $this->isModified = true; unset($this->sessionValues[$key]); $this->session->remove(self::encryptedSessionName); + if ($reopened) { + $this->close(); + } } /** @@ -149,6 +162,10 @@ class CryptoSessionData implements \ArrayAccess, ISession { $this->session->clear(); } + public function reopen(): bool { + return $this->session->reopen(); + } + /** * Wrapper around session_regenerate_id * |