Skip to content

Commit

Permalink
chore: addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwarajanand committed Feb 11, 2023
1 parent 619e7a9 commit aed0f23
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Spanner/src/Session/CacheSessionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ public function release(Session $session)
$name = $session->name();

if (isset($data['inUse'][$name])) {
$creationTime = $data['inUse'][$name]['creation'];
// set creation time to an expired time if no value is found
$creationTime = isset($data['inUse'][$name]['creation'])
? $data['inUse'][$name]['creation']
: $this->time() - self::DURATION_SESSION_LIFETIME;
unset($data['inUse'][$name]);
array_push($data['queue'], [
'name' => $name,
Expand Down Expand Up @@ -720,15 +723,19 @@ private function createSessions($count)
*/
private function isSessionValid(array $session)
{
$halfHourBeforeExpiration = $session['expiration'] - (SessionPoolInterface::SESSION_EXPIRATION_SECONDS / 2);
$halfHourBeforeExpiration = $session['expiration'] - 1800;

// sessions more than 28 days old are auto deleted by server
if (self::DURATION_SESSION_LIFETIME + $session['creation'] <
$this->time() + SessionPoolInterface::SESSION_EXPIRATION_SECONDS) {
// sessions more than 28 days old are auto deleted by server
return false;
} elseif ($this->time() < $halfHourBeforeExpiration) {
}
// session expires in more than half hour
if ($this->time() < $halfHourBeforeExpiration) {
return true;
} elseif ($halfHourBeforeExpiration < $this->time() && $this->time() < $session['expiration']) {
}
// session expires in less than a half hour, but is not expired
if ($this->time() < $session['expiration']) {
return $this->database
->session($session['name'])
->exists();
Expand Down

0 comments on commit aed0f23

Please sign in to comment.