Skip to content

Commit 90b4e4f

Browse files
authored
Merge pull request #7086 from nextcloud/perf/filesystem-setup
perf: Cache read only state for pushing steps
2 parents 20b54ec + 1fa5b84 commit 90b4e4f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

lib/Service/DocumentService.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function writeDocumentState(int $documentId, string $content): void {
206206
*/
207207
public function addStep(Document $document, Session $session, array $steps, int $version, ?string $shareToken): array {
208208
$documentId = $session->getDocumentId();
209-
$readOnly = $this->isReadOnly($this->getFileForSession($session, $shareToken), $shareToken);
209+
$readOnly = $this->isReadOnlyCached($session, $shareToken);
210210
$stepsToInsert = [];
211211
$stepsIncludeQuery = false;
212212
$documentState = null;
@@ -564,6 +564,18 @@ public function getFileByShareToken(string $shareToken, ?string $path = null): F
564564
throw new \InvalidArgumentException('No proper share data');
565565
}
566566

567+
public function isReadOnlyCached(Session $session, ?string $shareToken = null): bool {
568+
$cacheKey = 'read-only-' . $session->getId();
569+
$isReadOnly = $this->cache->get($cacheKey);
570+
if ($isReadOnly === null) {
571+
$file = $this->getFileForSession($session, $shareToken);
572+
$isReadOnly = $this->isReadOnly($file, $shareToken);
573+
$this->cache->set($cacheKey, $isReadOnly, 60 * 5);
574+
return $isReadOnly;
575+
}
576+
577+
return $isReadOnly;
578+
}
567579

568580
public function isReadOnly(File $file, ?string $token): bool {
569581
$readOnly = true;

0 commit comments

Comments
 (0)