Skip to content

Commit ef6d49a

Browse files
authored
Delete outputs on disk if outputs have been cleared. (#135)
1 parent b666a27 commit ef6d49a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

jupyter_server_documents/outputs/manager.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _process_loaded_no_placeholders(self, file_id: str, nb: dict) -> dict:
313313
cell['outputs'] = processed_outputs
314314
return nb
315315

316-
def process_saving_notebook(self, nb: dict) -> dict:
316+
def process_saving_notebook(self, nb: dict, file_id: str) -> dict:
317317
"""Process a notebook before saving to disk.
318318
319319
This method is called when the yroom_file_api saves notebooks.
@@ -322,6 +322,7 @@ def process_saving_notebook(self, nb: dict) -> dict:
322322
323323
Args:
324324
nb (dict): The notebook dict
325+
file_id (str): The file identifier
325326
326327
Returns:
327328
dict: The modified file data with placeholder_outputs set to True
@@ -337,6 +338,12 @@ def process_saving_notebook(self, nb: dict) -> dict:
337338
# Clear outputs for all code cells, as they are saved to disk
338339
for cell in nb.get('cells', []):
339340
if cell.get('cell_type') == 'code':
341+
# If outputs is already an empty list, call clear for this cell
342+
if cell.get('outputs') == []:
343+
cell_id = cell.get('id')
344+
if cell_id:
345+
self.clear(file_id, cell_id)
346+
340347
cell['outputs'] = []
341348

342349
return nb

jupyter_server_documents/rooms/yroom_file_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ async def save(self, jupyter_ydoc: YBaseDoc):
376376
self._save_scheduled = False
377377

378378
if self.file_type == "notebook":
379-
content = self.outputs_manager.process_saving_notebook(content)
379+
content = self.outputs_manager.process_saving_notebook(content, self.file_id)
380380

381381
# Save the YDoc via the ContentsManager
382382
async with self._content_lock:

0 commit comments

Comments
 (0)