diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2020-09-07 16:05:14 +0300 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-09-07 16:05:14 +0300 |
commit | 7e30b25ec0d427b447f5ca7305d2e18c083bcb14 (patch) | |
tree | 59c75ad455380d5eccfaa6b55e93fc6470240ce9 | |
parent | 37c68dfce000ffb6de27f3d3c0374365ed1ab173 (diff) |
Refresh lastContact only once every 30 seconds
Improvements for #1005
Just storing this less often should be a bit easier on the database.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-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; } |