Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] remove caching for shares #1750

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 0 additions & 6 deletions lib/Service/MembershipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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;
Expand Down
54 changes: 4 additions & 50 deletions lib/Service/ShareWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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,
) {
}


Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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());
}

Expand All @@ -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);
}

Expand All @@ -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, '');
}

Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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
Expand All @@ -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());

Expand Down
Loading