-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sync): cache steps in sync service
Store the steps that need to be send where we also do the debouncing. They will be updated whenever there is a new message from y-websocket. Signed-off-by: Max <max@nextcloud.com>
- Loading branch information
1 parent
f3ca9a9
commit 36048c1
Showing
6 changed files
with
95 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { encodeArrayBuffer } from '../helpers/base64.js' | ||
import { logger } from '../helpers/logger.js' | ||
|
||
export default class Outbox { | ||
|
||
#awarenessUpdate = '' | ||
#syncUpdate = '' | ||
#syncQuery = '' | ||
|
||
storeStep(step) { | ||
const encoded = encodeArrayBuffer(step) | ||
if (encoded < 'AAA' || encoded > 'Ag') { | ||
logger.warn('Unexpected step type:', { step, encoded }) | ||
return | ||
} | ||
if (encoded < 'AAE') { | ||
this.#syncQuery = encoded | ||
return | ||
} | ||
if (encoded < 'AQ') { | ||
this.#syncUpdate = encoded | ||
return | ||
} | ||
this.#awarenessUpdate = encoded | ||
} | ||
|
||
getDataToSend() { | ||
return { | ||
steps: [this.#syncUpdate, this.#syncQuery].filter(s => s), | ||
awareness: this.#awarenessUpdate, | ||
} | ||
} | ||
|
||
get hasUpdate() { | ||
return !!this.#syncUpdate | ||
} | ||
|
||
/* | ||
* Clear data that has just been sent. | ||
* | ||
* Only clear data that has not changed in the meantime. | ||
* @param {Sendable} - data that was to the server | ||
*/ | ||
clearSentData({ steps, awareness }) { | ||
if (steps.includes(this.#syncUpdate)) { | ||
this.#syncUpdate = '' | ||
} | ||
if (steps.includes(this.#syncQuery)) { | ||
this.#syncQuery = '' | ||
} | ||
if (this.#awarenessUpdate === awareness) { | ||
this.#awarenessUpdate = '' | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.