From bb4114ef26de3575cf24ea068c72646a855f25e0 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 769fd8926..53ab2d09f 100644 --- a/lib/Service/MembershipService.php +++ b/lib/Service/MembershipService.php @@ -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()); } } @@ -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; diff --git a/lib/Service/ShareWrapperService.php b/lib/Service/ShareWrapperService.php index 7373f5a15..ba62175d9 100644 --- a/lib/Service/ShareWrapperService.php +++ b/lib/Service/ShareWrapperService.php @@ -38,12 +38,9 @@ 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\NotFoundException; -use OCP\ICache; -use OCP\ICacheFactory; use OCP\Share\IShare; use OCP\Files\Folder; @@ -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, + ) { } @@ -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); } @@ -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); } @@ -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()); } @@ -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); } @@ -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, ''); } @@ -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); } @@ -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 @@ -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());