Skip to content

Commit

Permalink
remove caching for shares
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl authored and backportbot[bot] committed Nov 11, 2024
1 parent d5250ed commit 7dbd10b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 56 deletions.
6 changes: 0 additions & 6 deletions lib/Service/MembershipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,6 @@ function (Membership $membership): string {
if (!in_array($item->getCircleId(), $circleIds)) {
$deprecated[] = $item;
$this->membershipRequest->delete($item);

// clearing the getSharedWith() cache for singleId related to the membership
$this->shareWrapperService->clearCache($item->getSingleId());
}
}

Expand Down Expand Up @@ -382,9 +379,6 @@ private function createNewMemberships(array $memberships, array $known): array {
$this->membershipRequest->insert($membership);
$new[] = $membership;
}

// clearing the getSharedWith() cache for singleId related to the membership
$this->shareWrapperService->clearCache($membership->getSingleId());
}

return $new;
Expand Down
54 changes: 4 additions & 50 deletions lib/Service/ShareWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Model\ShareWrapper;
use OCA\Circles\Tools\Exceptions\InvalidItemException;
use OCA\Circles\Tools\Traits\TDeserialize;
use OCA\Circles\Tools\Traits\TStringTools;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\Share\IShare;

/**
Expand All @@ -56,26 +53,9 @@ class ShareWrapperService {
use TStringTools;
use TDeserialize;

public const CACHE_SHARED_WITH = 'circles/getSharedWith';
public const CACHE_SHARED_WITH_TTL = 900;


/** @var ShareWrapperRequest */
private $shareWrapperRequest;

private ICache $cache;


/**
* ShareWrapperService constructor.
*
* @param ICacheFactory $cacheFactory
* @param ShareWrapperRequest $shareWrapperRequest
*/
public function __construct(ICacheFactory $cacheFactory, ShareWrapperRequest $shareWrapperRequest) {
$this->cache = $cacheFactory->createDistributed(self::CACHE_SHARED_WITH);

$this->shareWrapperRequest = $shareWrapperRequest;
public function __construct(
private ShareWrapperRequest $shareWrapperRequest,
) {
}


Expand All @@ -98,7 +78,6 @@ public function searchShare(string $singleId, int $nodeId): ShareWrapper {
* @throws NotFoundException
*/
public function save(IShare $share): void {
$this->cache->clear('');
$this->shareWrapperRequest->save($share);
}

Expand All @@ -107,7 +86,6 @@ public function save(IShare $share): void {
* @param ShareWrapper $shareWrapper
*/
public function update(ShareWrapper $shareWrapper): void {
$this->cache->clear('');
$this->shareWrapperRequest->update($shareWrapper);
}

Expand All @@ -116,7 +94,6 @@ public function update(ShareWrapper $shareWrapper): void {
* @param ShareWrapper $shareWrapper
*/
public function delete(ShareWrapper $shareWrapper): void {
$this->cache->clear('');
$this->shareWrapperRequest->delete((int)$shareWrapper->getId());
}

Expand All @@ -131,7 +108,6 @@ public function deleteUserSharesToCircle(string $circleId, string $userId): void
throw new Exception('$initiator cannot be empty');
}

$this->cache->clear('');
$this->shareWrapperRequest->deleteSharesToCircle($circleId, $userId);
}

Expand All @@ -140,7 +116,6 @@ public function deleteUserSharesToCircle(string $circleId, string $userId): void
* @param string $circleId
*/
public function deleteAllSharesToCircle(string $circleId): void {
$this->cache->clear('');
$this->shareWrapperRequest->deleteSharesToCircle($circleId, '');
}

Expand Down Expand Up @@ -230,22 +205,7 @@ public function getSharedWith(
int $nodeId,
?CircleProbe $probe
): array {
$key = $this->generateSharedWithCacheKey($federatedUser, $nodeId, $probe->getChecksum());

$cachedData = $this->cache->get($key);
try {
if (!is_string($cachedData)) {
throw new InvalidItemException();
}

return $this->deserializeList($cachedData, ShareWrapper::class);
} catch (InvalidItemException $e) {
}

$shares = $this->shareWrapperRequest->getSharedWith($federatedUser, $nodeId, $probe);
$this->cache->set($key, json_encode($shares), self::CACHE_SHARED_WITH_TTL);

return $shares;
return $this->shareWrapperRequest->getSharedWith($federatedUser, $nodeId, $probe);
}


Expand Down Expand Up @@ -309,11 +269,6 @@ public function getChild(IShare $share, FederatedUser $federatedUser): ShareWrap
}


public function clearCache(string $singleId): void {
$this->cache->clear($singleId);
}


/**
* @param FederatedUser $federatedUser
* @param IShare $share
Expand All @@ -324,7 +279,6 @@ public function clearCache(string $singleId): void {
* @throws RequestBuilderException
*/
private function createChild(IShare $share, FederatedUser $federatedUser): ShareWrapper {
$this->cache->clear('');
$share->setSharedWith($federatedUser->getSingleId());
$childId = $this->shareWrapperRequest->save($share, (int)$share->getId());

Expand Down

0 comments on commit 7dbd10b

Please sign in to comment.