-
-
Notifications
You must be signed in to change notification settings - Fork 43
Respect autosave setting in RTC backend #479
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
Changes from 5 commits
c9d8dc8
789c874
40fba54
19a0335
45b9ec2
cecb9eb
de5267e
28c1ac9
72fd92b
7e84bf8
6b94adb
9ddd24d
cd23070
518fec4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,7 @@ import { | |||||||
ISharedModelFactory | ||||||||
} from '@jupyter/collaborative-drive'; | ||||||||
import { Awareness } from 'y-protocols/awareness'; | ||||||||
import { ISettingRegistry } from '@jupyterlab/settingregistry'; | ||||||||
|
||||||||
const DISABLE_RTC = | ||||||||
PageConfig.getOption('disableRTC') === 'true' ? true : false; | ||||||||
|
@@ -42,6 +43,7 @@ namespace RtcContentProvider { | |||||||
user: User.IManager; | ||||||||
trans: TranslationBundle; | ||||||||
globalAwareness: Awareness | null; | ||||||||
docmanagerSettings: ISettingRegistry.ISettings | null; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
@@ -57,6 +59,7 @@ export class RtcContentProvider | |||||||
this._serverSettings = options.serverSettings; | ||||||||
this.sharedModelFactory = new SharedModelFactory(this._onCreate); | ||||||||
this._providers = new Map<string, WebSocketProvider>(); | ||||||||
this._docmanagerSettings = options.docmanagerSettings; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
|
@@ -123,7 +126,7 @@ export class RtcContentProvider | |||||||
const provider = this._providers.get(key); | ||||||||
|
||||||||
if (provider) { | ||||||||
// Save is done from the backend | ||||||||
provider.wsProvider?.ws?.send('save_to_disc'); | ||||||||
|
this._ydriveFileChanged.emit({ | |
type: 'save', | |
newValue: { ...model, hash: hashChange.newValue }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also include autosaveInterval
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should also send the autosaveInterval
to the backend?
The reason I ask is that currently, JupyterLab (frontend) automatically calls save
after every autosaveInterval
, which in turn triggers save_to_disc
on the backend.
However, the current implementation is that when autosave is enabled, the backend saves the document to disk on every document change, regardless of the configured autosave interval.
If we want to respect the autosave interval properly, I think we could consider removing the _on_document_change
function on the backend.
jupyter-collaboration/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py
Lines 235 to 237 in 9059310
def _on_document_change(self, target: str, event: Any) -> None: | |
""" | |
Called when the shared document changes. |
Here's why:
- When autosave is off, only manual saves are possible, so observing document changes for saving might not be necessary.
- When autosave is on, the client will already call
save
at the configured interval, which will triggersave_to_disc
. Thus, observing document changes on the backend may also be redundant in this case.
One potential caveat is that if multiple clients with different autosaveInterval
values are connected to the same document, save_to_disc
will still be called for each of them when their individual autosave timers trigger.
Would love to hear your thoughts on this approach and whether you see any concerns or alternatives.
CC: @davidbrochart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should move the discussion to a new issue and address this in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is reasonable. We could create a new issue after this PR gets merged.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,8 +290,15 @@ async def on_message(self, message): | |
""" | ||
On message receive. | ||
""" | ||
message_type = message[0] | ||
if message == "save_to_disc": | ||
|
||
try: | ||
self.room._saving_document = asyncio.create_task( | ||
self.room._maybe_save_document(self.room._saving_document) | ||
) | ||
except Exception: | ||
self.log.error("Couldn't save content from room: %s", self._room_id) | ||
|
||
message_type = message[0] | ||
Darshan808 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if message_type == MessageType.CHAT: | ||
msg = message[2:].decode("utf-8") | ||
davidbrochart marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
@@ -321,7 +328,7 @@ def on_close(self) -> None: | |
""" | ||
# stop serving this client | ||
self._message_queue.put_nowait(b"") | ||
if isinstance(self.room, DocumentRoom) and self.room.clients == [self]: | ||
if isinstance(self.room, DocumentRoom) and self.room.clients == {self}: | ||
# no client in this room after we disconnect | ||
# keep the document for a while in case someone reconnects | ||
self.log.info("Cleaning room: %s", self._room_id) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this change user's autosave setting? I think we could just take the value as-is because autosave is the default in lab and notebook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, if autosave is set to true by default, then we don't need this.
Let me go ahead and remove it.