Skip to content
Closed
Changes from all commits
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
42 changes: 42 additions & 0 deletions lib/Share/RoomShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\Files\Folder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\Node;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\Security\ISecureRandom;
Expand Down Expand Up @@ -83,6 +84,7 @@ public function __construct(
protected ITimeFactory $timeFactory,
protected IL10N $l,
protected IMimeTypeLoader $mimeTypeLoader,
protected ICacheFactory $cacheFactory,
) {
$this->sharesByIdCache = new CappedMemoryCache();
}
Expand Down Expand Up @@ -215,6 +217,9 @@ private function addShareToDB(
$insert->executeStatement();
$id = $insert->getLastInsertId();

$genCache = $this->cacheFactory->createDistributed('talk/shares');
$genCache->set('generationId', $id);

return $id;
}

Expand Down Expand Up @@ -805,6 +810,35 @@ public function getSharesByPath(Node $path): array {
public function getSharedWith($userId, $shareType, $node, $limit, $offset): array {
$allRooms = $this->manager->getRoomTokensForUser($userId);

$cacheKey = null;
$cacheKeySuffix = $node === null && $limit === -1 && $offset === 0 ? sha1(json_encode($allRooms)) : null;
if ($cacheKeySuffix) {
$genCache = $this->cacheFactory->createDistributed('talk/shares');
$generationId = $genCache->get('generationId');
if ($generationId !== null) {
$localCache = $this->cacheFactory->createLocal('talk/shares');
$cacheKey = $generationId . '$' . $cacheKeySuffix;
$cachedData = $localCache->get($cacheKey);
if ($cachedData === 'empty') {
return [];
}
} else {
// To warm up the cache, we query the maximum ID from oc_share
// and store it as generationId in the distributed cache.
$query = $this->dbConnection->getQueryBuilder();
$query->select('id')
->from('share')
->orderBy('id', 'DESC')
->setMaxResults(1);
$result = $query->executeQuery();
$generationId = (int) $result->fetchOne();
$result->closeCursor();

$genCache->set('generationId', $generationId);
$cacheKey = $generationId . '$' . $cacheKeySuffix;
}
}

$query = $this->dbConnection->getQueryBuilder();
$query->select('s.*')
->from('share', 's')
Expand Down Expand Up @@ -842,6 +876,14 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
$result->closeCursor();
}

if (empty($shareRows) && $cacheKey) {
if (!isset($localCache)) {
$localCache = $this->cacheFactory->createLocal('talk/shares');
}
$localCache->set($cacheKey, 'empty', 300);
return [];
}

$queryFileCache = $this->dbConnection->getQueryBuilder();
$queryFileCache->select('f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
Expand Down