-
-
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 10 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'); | ||||||||
const fetchOptions: Contents.IFetchOptions = { | ||||||||
type: options.type, | ||||||||
format: options.format, | ||||||||
|
@@ -150,6 +153,19 @@ export class RtcContentProvider | |||||||
if (typeof options.format !== 'string') { | ||||||||
return; | ||||||||
} | ||||||||
// Set initial autosave value, used to determine backend autosave (default: true) | ||||||||
const autosave = | ||||||||
(this._docmanagerSettings?.composite?.['autosave'] as boolean) ?? true; | ||||||||
|
||||||||
sharedModel.awareness.setLocalStateField('autosave', autosave); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we should also send the The reason I ask is that currently, JupyterLab (frontend) automatically calls If we want to respect the autosave interval properly, I think we could consider removing the jupyter-collaboration/projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py Lines 235 to 237 in 9059310
Here's why:
One potential caveat is that if multiple clients with different 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 commentThe 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 commentThe 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. |
||||||||
|
||||||||
// Watch for changes in settings | ||||||||
this._docmanagerSettings?.changed.connect(() => { | ||||||||
const newAutosave = | ||||||||
(this._docmanagerSettings?.composite?.['autosave'] as boolean) ?? true; | ||||||||
sharedModel.awareness.setLocalStateField('autosave', newAutosave); | ||||||||
}); | ||||||||
|
||||||||
try { | ||||||||
const provider = new WebSocketProvider({ | ||||||||
url: URLExt.join(this._serverSettings.wsUrl, DOCUMENT_PROVIDER_URL), | ||||||||
|
@@ -235,6 +251,7 @@ export class RtcContentProvider | |||||||
private _providers: Map<string, WebSocketProvider>; | ||||||||
private _ydriveFileChanged = new Signal<this, Contents.IChangedArgs>(this); | ||||||||
private _serverSettings: ServerConnection.ISettings; | ||||||||
private _docmanagerSettings: ISettingRegistry.ISettings | null; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from logging import Logger | ||
from typing import Any | ||
from uuid import uuid4 | ||
from typing import cast | ||
|
||
from jupyter_server.auth import authorized | ||
from jupyter_server.base.handlers import APIHandler, JupyterHandler | ||
|
@@ -291,6 +292,16 @@ async def on_message(self, message): | |
""" | ||
On message receive. | ||
""" | ||
if message == "save_to_disc": | ||
|
||
try: | ||
room = cast(DocumentRoom, self.room) | ||
room._saving_document = asyncio.create_task( | ||
room._maybe_save_document(room._saving_document) | ||
) | ||
except Exception: | ||
self.log.error("Couldn't save content from room: %s", self._room_id) | ||
return | ||
|
||
self._message_queue.put_nowait(message) | ||
self._websocket_server.ypatch_nb += 1 | ||
|
||
|
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 we should use a custom message type (see here). Maybe
2
followed bysave
?Also, should we wait for a reply indicating that the file has indeed been saved? Otherwise the following
get
will probably not return the state of the saved file.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.
True, But since the signal below is fired after each save from server (due to hash change) and the contents model is automatically updated with the new values, it may not be necessary to wait for the reply here to update the contents model.
jupyter-collaboration/packages/docprovider/src/ydrive.ts
Lines 198 to 200 in 9059310