Skip to content

Commit

Permalink
remove global variable keeping track of undo managers
Browse files Browse the repository at this point in the history
remove global variable keeping track of undo managers

remove print
  • Loading branch information
Meriem-BenIsmail committed Aug 28, 2024
1 parent 0c2c367 commit c2e139e
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@


SERVER_SESSION = str(uuid.uuid4())
UNDO_MANAGERS = {}
FORK_DOCUMENTS = {}


Expand Down Expand Up @@ -491,7 +490,7 @@ async def get(self, path: str) -> None:
FORK_DOCUMENTS[idx] = ydoc_factory(fork_ydoc)

undo_manager: UndoManager = FORK_DOCUMENTS[idx].undo_manager
UNDO_MANAGERS[idx] = undo_manager

updates_and_timestamps = [(item[0], item[-1]) async for item in room.ystore.read()]

result_timestamps = []
Expand Down Expand Up @@ -529,18 +528,13 @@ async def put(self, room_id):
steps = int(self.request.query_arguments.get("steps")[0].decode("utf-8"))
fork_room_id = str(self.request.query_arguments.get("forkRoom")[0].decode("utf-8"))

undo_manager = UNDO_MANAGERS[fork_room_id]

if not undo_manager:
self.set_status(404)
return self.finish({"code": 404, "error": "Undo Manager not found"})

fork_document = FORK_DOCUMENTS[fork_room_id]

if not fork_document:
self.set_status(404)
return self.finish({"code": 404, "error": "Fork document not found"})

undo_manager = fork_document.undo_manager

if action == "undo":
if undo_manager.can_undo():
await self._perform_undo_or_redo(undo_manager, "undo", steps)
Expand Down Expand Up @@ -588,6 +582,6 @@ async def _perform_undo_or_redo(
break

async def _cleanup_undo_manager(self, room_id: str) -> None:
if room_id in UNDO_MANAGERS:
del UNDO_MANAGERS[room_id]
print(f"UndoManager for {room_id} has been removed.")
if room_id in FORK_DOCUMENTS:
del FORK_DOCUMENTS[room_id]
print(f"Fork Document for {room_id} has been removed.")

0 comments on commit c2e139e

Please sign in to comment.