Skip to content

Commit c64ff08

Browse files
committed
enh(syn): log first recovery attempt as error in the server
Signed-off-by: Jonas <jonas@freesources.org>
1 parent bf782c8 commit c64ff08

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

lib/Controller/PublicSessionController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public function close(int $documentId, int $sessionId, string $sessionToken): Da
7878
#[PublicPage]
7979
#[RequireDocumentBaseVersionEtag]
8080
#[RequireDocumentSession]
81-
public function push(int $documentId, int $sessionId, string $sessionToken, int $version, array $steps, string $awareness, string $token): DataResponse {
82-
return $this->apiService->push($this->getSession(), $this->getDocument(), $version, $steps, $awareness, $token);
81+
public function push(int $documentId, int $sessionId, string $sessionToken, int $version, array $steps, string $awareness, string $token, ?int $recoveryAttempt = null): DataResponse {
82+
return $this->apiService->push($this->getSession(), $this->getDocument(), $version, $steps, $awareness, $recoveryAttempt, $token);
8383
}
8484

8585
#[NoAdminRequired]

lib/Controller/SessionController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public function close(int $documentId, int $sessionId, string $sessionToken): Da
5656
#[PublicPage]
5757
#[RequireDocumentBaseVersionEtag]
5858
#[RequireDocumentSession]
59-
public function push(int $version, array $steps, string $awareness): DataResponse {
59+
public function push(int $version, array $steps, string $awareness, ?int $recoveryAttempt = null): DataResponse {
6060
try {
6161
$this->loginSessionUser();
62-
return $this->apiService->push($this->getSession(), $this->getDocument(), $version, $steps, $awareness);
62+
return $this->apiService->push($this->getSession(), $this->getDocument(), $version, $steps, $awareness, $recoveryAttempt);
6363
} finally {
6464
$this->restoreSessionUser();
6565
}

lib/Service/ApiService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ public function close(int $documentId, int $sessionId, string $sessionToken): Da
174174
/**
175175
* @throws NotFoundException
176176
*/
177-
public function push(Session $session, Document $document, int $version, array $steps, string $awareness, ?string $token = null): DataResponse {
177+
public function push(Session $session, Document $document, int $version, array $steps, string $awareness, ?int $recoveryAttempt, ?string $token = null): DataResponse {
178178
try {
179179
$session = $this->sessionService->updateSessionAwareness($session, $awareness);
180180
} catch (DoesNotExistException $e) {
181181
// Session was removed in the meantime. #3875
182182
return new DataResponse(['error' => $this->l10n->t('Editing session has expired. Please reload the page.')], Http::STATUS_PRECONDITION_FAILED);
183183
}
184184
try {
185-
$result = $this->documentService->addStep($document, $session, $steps, $version, $token);
185+
$result = $this->documentService->addStep($document, $session, $steps, $version, $recoveryAttempt, $token);
186186
$this->addToPushQueue($document, [$awareness, ...array_values($steps)]);
187187
} catch (InvalidArgumentException $e) {
188188
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_UNPROCESSABLE_ENTITY);

lib/Service/DocumentService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function writeDocumentState(int $documentId, string $content): void {
205205
* @throws NotPermittedException
206206
* @throws DoesNotExistException
207207
*/
208-
public function addStep(Document $document, Session $session, array $steps, int $version, ?string $shareToken): array {
208+
public function addStep(Document $document, Session $session, array $steps, int $version, ?int $recoveryAttempt, ?string $shareToken): array {
209209
$documentId = $session->getDocumentId();
210210
$readOnly = $this->isReadOnlyCached($session, $shareToken);
211211
$stepsToInsert = [];
@@ -234,6 +234,11 @@ public function addStep(Document $document, Session $session, array $steps, int
234234
// By default, send all steps the user has not received yet.
235235
$getStepsSinceVersion = $version;
236236
if ($stepsIncludeQuery) {
237+
if ($recoveryAttempt === 1) {
238+
$this->logger->error('Recovery attempt #' . $recoveryAttempt . ' from ' . $session->getId() . ' for ' . $documentId);
239+
} elseif ($recoveryAttempt > 1) {
240+
$this->logger->debug('Recovery attempt #' . $recoveryAttempt . ' from ' . $session->getId() . ' for ' . $documentId);
241+
}
237242
$this->logger->debug('Loading document state for ' . $documentId);
238243
try {
239244
$stateFile = $this->getStateFile($documentId);

src/apis/sync.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface PushData {
1313
version: number
1414
steps: string[]
1515
awareness: string
16+
recoveryAttempt?: number
1617
}
1718

1819
interface PushResponse {
@@ -44,6 +45,7 @@ export function push(
4445
version: data.version,
4546
steps: data.steps.filter((s) => s),
4647
awareness: data.awareness,
48+
recoveryAttempt: data.recoveryAttempt,
4749
})
4850
}
4951

src/helpers/yjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function documentStateToUpdateMessage(documentState: string): Uint8Array {
7171
* Only used in tests right now.
7272
* @param ydoc - encode state of this doc
7373
* @param step - step data
74-
* @param step.step - base64 encoded yjs sync update message
74+
* @param step.data - array of base64 encoded yjs sync update messages
7575
* @param origin - initiator object e.g. WebsocketProvider
7676
*/
7777
export function applyStep(ydoc: Y.Doc, step: Step, origin = 'origin') {

0 commit comments

Comments
 (0)