Skip to content
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

Fix slow room opening #264

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions jupyter_collaboration/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ async def _clean_room(self) -> None:
contains a copy of the document. In addition, we remove the file if there is no rooms
subscribed to it.
"""
async with self._room_lock(self._room_id):
assert isinstance(self.room, DocumentRoom)
assert isinstance(self.room, DocumentRoom)

if self._cleanup_delay is None:
return
if self._cleanup_delay is None:
return

await asyncio.sleep(self._cleanup_delay)
await asyncio.sleep(self._cleanup_delay)

async with self._room_lock(self._room_id):
# Remove the room from the websocket server
self.log.info("Deleting Y document from memory: %s", self.room.room_id)
self._websocket_server.delete_room(room=self.room)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,25 @@ async def connect(file_format, file_type, file_path):
tg.start_soon(connect, file_format, file_type, file_path)
t1 = time()
assert t1 - t0 < 0.5


async def test_room_sequential_opening(
rtc_create_file,
rtc_connect_doc_client,
):
file_format = "text"
file_type = "file"
file_path = "dummy.txt"
await rtc_create_file(file_path)

async def connect(file_format, file_type, file_path):
t0 = time()
async with await rtc_connect_doc_client(file_format, file_type, file_path) as ws:
pass
t1 = time()
return t1 - t0

dt = await connect(file_format, file_type, file_path)
assert dt < 1
dt = await connect(file_format, file_type, file_path)
assert dt < 1
Loading