From 54eba11c76a4b3616c8cca8bd2165d5aa41da767 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 7 Nov 2024 14:54:49 -0100 Subject: [PATCH] remove caching for shares Signed-off-by: Maxence Lange --- lib/Service/MembershipService.php | 6 ---- lib/Service/ShareWrapperService.php | 54 +++-------------------------- 2 files changed, 4 insertions(+), 56 deletions(-) diff --git a/lib/Service/MembershipService.php b/lib/Service/MembershipService.php index 50f984dde..968477722 100644 --- a/lib/Service/MembershipService.php +++ b/lib/Service/MembershipService.php @@ -330,9 +330,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()); } } @@ -362,9 +359,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; diff --git a/lib/Service/ShareWrapperService.php b/lib/Service/ShareWrapperService.php index 171b9c9a6..5be6bee51 100644 --- a/lib/Service/ShareWrapperService.php +++ b/lib/Service/ShareWrapperService.php @@ -18,13 +18,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; /** @@ -36,26 +33,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, + ) { } @@ -78,7 +58,6 @@ public function searchShare(string $singleId, int $nodeId): ShareWrapper { * @throws NotFoundException */ public function save(IShare $share): void { - $this->cache->clear(''); $this->shareWrapperRequest->save($share); } @@ -87,7 +66,6 @@ public function save(IShare $share): void { * @param ShareWrapper $shareWrapper */ public function update(ShareWrapper $shareWrapper): void { - $this->cache->clear(''); $this->shareWrapperRequest->update($shareWrapper); } @@ -96,7 +74,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()); } @@ -111,7 +88,6 @@ public function deleteUserSharesToCircle(string $circleId, string $userId): void throw new Exception('$initiator cannot be empty'); } - $this->cache->clear(''); $this->shareWrapperRequest->deleteSharesToCircle($circleId, $userId); } @@ -120,7 +96,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, ''); } @@ -210,22 +185,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); } @@ -289,11 +249,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 @@ -304,7 +259,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());