Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cache the last token activity for 10 minutes
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Jun 22, 2020
commit 35fde92ac0d3505244d8d5c0f7bae98e4d31eb12
21 changes: 20 additions & 1 deletion lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use OCP\AppFramework\Http;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Http\Client\IClientService;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\ILogger;
Expand All @@ -53,19 +55,30 @@ class Push {
private $userManager;
/** @var IClientService */
protected $clientService;
/** @var ICache */
protected $cache;
/** @var ILogger */
protected $log;
/** @var OutputInterface */
protected $output;

public function __construct(IDBConnection $connection, INotificationManager $notificationManager, IConfig $config, IProvider $tokenProvider, Manager $keyManager, IUserManager $userManager, IClientService $clientService, ILogger $log) {
public function __construct(IDBConnection $connection,
INotificationManager $notificationManager,
IConfig $config,
IProvider $tokenProvider,
Manager $keyManager,
IUserManager $userManager,
IClientService $clientService,
ICacheFactory $cacheFactory,
ILogger $log) {
$this->db = $connection;
$this->notificationManager = $notificationManager;
$this->config = $config;
$this->tokenProvider = $tokenProvider;
$this->keyManager = $keyManager;
$this->userManager = $userManager;
$this->clientService = $clientService;
$this->cache = $cacheFactory->createDistributed('pushtokens');
$this->log = $log;
}

Expand Down Expand Up @@ -266,9 +279,15 @@ protected function sendNotificationsToProxies(array $pushNotifications): void {
}

protected function validateToken(int $tokenId, int $maxAge): bool {
$age = $this->cache->get('t' . $tokenId);
if ($age !== null) {
return $age > $maxAge;
}

try {
// Check if the token is still valid...
$token = $this->tokenProvider->getTokenById($tokenId);
$this->cache->set('t' . $tokenId, $token->getLastCheck(), 600);
return $token->getLastCheck() > $maxAge;
} catch (InvalidTokenException $e) {
// Token does not exist anymore, should drop the push device entry
Expand Down