Skip to content

Commit

Permalink
Fix slow room opening (#264)
Browse files Browse the repository at this point in the history
* Fix slow room opening

* Add fix
  • Loading branch information
davidbrochart authored Mar 27, 2024
1 parent 35a515c commit 8f55ea5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
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

0 comments on commit 8f55ea5

Please sign in to comment.