Skip to content
Snippets Groups Projects

Use the readSessions() property on read too.

Open catch requested to merge issue/drupal-3410601:3410601-optimize-sessions-reads into 11.x
Files
2
@@ -25,7 +25,7 @@ class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSess
@@ -25,7 +25,7 @@ class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSess
* @var array
* @var array
* Session data keyed by the session ID.
* Session data keyed by the session ID.
*/
*/
private $readSessions;
private array $readSessions = [];
/**
/**
* Constructs a new write safe session handler.
* Constructs a new write safe session handler.
@@ -45,6 +45,7 @@ public function __construct(\SessionHandlerInterface $wrapped_session_handler, $
@@ -45,6 +45,7 @@ public function __construct(\SessionHandlerInterface $wrapped_session_handler, $
*/
*/
#[\ReturnTypeWillChange]
#[\ReturnTypeWillChange]
public function close() {
public function close() {
 
$this->readSessions = [];
return $this->wrappedSessionHandler->close();
return $this->wrappedSessionHandler->close();
}
}
@@ -53,6 +54,7 @@ public function close() {
@@ -53,6 +54,7 @@ public function close() {
*/
*/
#[\ReturnTypeWillChange]
#[\ReturnTypeWillChange]
public function destroy($session_id) {
public function destroy($session_id) {
 
unset($this->readSessions[$session_id]);
return $this->wrappedSessionHandler->destroy($session_id);
return $this->wrappedSessionHandler->destroy($session_id);
}
}
@@ -77,6 +79,9 @@ public function open($save_path, $session_id) {
@@ -77,6 +79,9 @@ public function open($save_path, $session_id) {
*/
*/
#[\ReturnTypeWillChange]
#[\ReturnTypeWillChange]
public function read($session_id) {
public function read($session_id) {
 
if (\array_key_exists($session_id, $this->readSessions)) {
 
return $this->readSessions[$session_id];
 
}
$value = $this->wrappedSessionHandler->read($session_id);
$value = $this->wrappedSessionHandler->read($session_id);
$this->readSessions[$session_id] = $value;
$this->readSessions[$session_id] = $value;
return $value;
return $value;
@@ -92,6 +97,7 @@ public function write($session_id, $session_data) {
@@ -92,6 +97,7 @@ public function write($session_id, $session_data) {
return TRUE;
return TRUE;
}
}
if ($this->isSessionWritable()) {
if ($this->isSessionWritable()) {
 
$this->readSessions[$session_id] = $session_data;
return $this->wrappedSessionHandler->write($session_id, $session_data);
return $this->wrappedSessionHandler->write($session_id, $session_data);
}
}
return TRUE;
return TRUE;
Loading