Skip to content

Commit c9866ab

Browse files
committed
chore(performance): only check permissions when changing content
Avoid setting up the file system for read only shares. Also clarify the behavior: Updates are silently dropped as they were before. Previously `stepsToInsert` would always be empty for readonly requests, due to the continue in the loop collecting the steps. So there was no way to trigger the ``` NotPermittedException('Read-only client tries to push steps with changes') ``` Keep this behavior for now so we can backport this commit. Clients on readonly shares regularly push updates to the server to update their awareness state - i.e. let others know they are still around. These requests trigger the addStep function even if they do not actually change the content of the file. Signed-off-by: Max <max@nextcloud.com>
1 parent 5fc7ed8 commit c9866ab

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

lib/Service/DocumentService.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,11 @@ public function writeDocumentState(int $documentId, string $content): void {
218218
*/
219219
public function addStep(Document $document, Session $session, array $steps, int $version, ?int $recoveryAttempt, ?string $shareToken): array {
220220
$documentId = $session->getDocumentId();
221-
$file = $this->getFileForSession($session, $shareToken);
222-
$readOnly = $this->isReadOnly($file, $shareToken);
223221
$stepsToInsert = [];
224222
$stepsIncludeQuery = false;
225223
$documentState = null;
226224
foreach ($steps as $step) {
227225
$message = YjsMessage::fromBase64($step);
228-
if ($readOnly && $message->isUpdate()) {
229-
continue;
230-
}
231226
// Only accept sync protocol
232227
if ($message->getYjsMessageType() !== YjsMessage::YJS_MESSAGE_SYNC) {
233228
continue;
@@ -240,10 +235,10 @@ public function addStep(Document $document, Session $session, array $steps, int
240235
}
241236
}
242237
if (count($stepsToInsert) > 0) {
243-
if ($readOnly) {
244-
throw new NotPermittedException('Read-only client tries to push steps with changes');
238+
$file = $this->getFileForSession($session, $shareToken);
239+
if (!$this->isReadOnly($file, $shareToken)) {
240+
$this->insertSteps($document, $session, $stepsToInsert);
245241
}
246-
$this->insertSteps($document, $session, $stepsToInsert);
247242
}
248243

249244
// By default, send all steps the user has not received yet.

0 commit comments

Comments
 (0)