diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-09-08 17:31:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-08 17:31:12 +0300 |
commit | 9b068d180ffcfc16f699468408285b871f087519 (patch) | |
tree | ef1242e0aea11f3ef4d4012fba53d41b675744bb /lib | |
parent | 77a64883c163e880ce65d23886488d336fa5a490 (diff) | |
parent | 928590d922eae92bd9b0caaa06b492e1dadfc1ad (diff) |
Merge pull request #1026 from nextcloud/fix/1005/refresh_only_once_every_30_s
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/Session.php | 1 | ||||
-rw-r--r-- | lib/Service/SessionService.php | 22 |
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/Db/Session.php b/lib/Db/Session.php index e13d95e90..9d727039e 100644 --- a/lib/Db/Session.php +++ b/lib/Db/Session.php @@ -27,6 +27,7 @@ namespace OCA\Text\Db; use OCP\AppFramework\Db\Entity; /** + * @method int getLastContact() * @method setLastContact(int $getTime) * @method getDocumentId() * @method getUserId() diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index 16d1fcabb..f70952d94 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -164,7 +164,7 @@ class SessionService { try { $data = $this->sessionMapper->find($documentId, $sessionId, $token); - $this->cache->set($token, json_encode($data), self::SESSION_VALID_TIME); + $this->cache->set($token, json_encode($data), self::SESSION_VALID_TIME - 30); return $data; } catch (DoesNotExistException $e) { $this->session = false; @@ -178,9 +178,23 @@ class SessionService { return false; } - $session->setLastContact($this->timeFactory->getTime()); - $this->sessionMapper->update($session); - $this->cache->set($token, json_encode($session), self::SESSION_VALID_TIME); + $currentTime = $this->timeFactory->getTime(); + if (($currentTime - $session->getLastContact()) >= 30) { + /* + * We need to update the timestamp. + * Make sure that the session we got is still in the database + */ + try { + $session = $this->sessionMapper->find($documentId, $sessionId, $token); + } catch (DoesNotExistException $e) { + $this->session = false; + $this->cache->remove($token); + return false; + } + $session->setLastContact($this->timeFactory->getTime()); + $this->sessionMapper->update($session); + $this->cache->set($token, json_encode($session), self::SESSION_VALID_TIME - 30); + } return true; } |