Skip to content

Commit 05baa15

Browse files
Call pre_save_hook only on first chunk of large files (#716)
* Call pre_save_hook only on first chunk of large files * Include chunk number in debug message
1 parent 653740c commit 05baa15

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

jupyter_server/services/contents/filemanager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,15 +775,16 @@ async def save(self, model, path=""):
775775
"""Save the file model and return the model with no content."""
776776
path = path.strip("/")
777777

778-
os_path = self._get_os_path(path)
779-
self.log.debug("Saving %s", os_path)
780778
self.run_pre_save_hook(model=model, path=path)
781779

782780
if "type" not in model:
783781
raise web.HTTPError(400, "No file type provided")
784782
if "content" not in model and model["type"] != "directory":
785783
raise web.HTTPError(400, "No file content provided")
786784

785+
os_path = self._get_os_path(path)
786+
self.log.debug("Saving %s", os_path)
787+
787788
try:
788789
if model["type"] == "notebook":
789790
nb = nbformat.from_dict(model["content"])

jupyter_server/services/contents/largefilemanager.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def save(self, model, path=""):
1818
if chunk is not None:
1919
path = path.strip("/")
2020

21-
self.run_pre_save_hook(model=model, path=path)
21+
if chunk == 1:
22+
self.run_pre_save_hook(model=model, path=path)
2223

2324
if "type" not in model:
2425
raise web.HTTPError(400, "No file type provided")
@@ -31,7 +32,10 @@ def save(self, model, path=""):
3132
raise web.HTTPError(400, "No file content provided")
3233

3334
os_path = self._get_os_path(path)
34-
self.log.debug("Saving %s", os_path)
35+
if chunk == -1:
36+
self.log.debug(f"Saving last chunk of file {os_path}")
37+
else:
38+
self.log.debug(f"Saving chunk {chunk} of file {os_path}")
3539

3640
try:
3741
if chunk == 1:
@@ -89,9 +93,8 @@ async def save(self, model, path=""):
8993
if chunk is not None:
9094
path = path.strip("/")
9195

92-
os_path = self._get_os_path(path)
93-
self.log.debug("Saving %s", os_path)
94-
self.run_pre_save_hook(model=model, path=path)
96+
if chunk == 1:
97+
self.run_pre_save_hook(model=model, path=path)
9598

9699
if "type" not in model:
97100
raise web.HTTPError(400, "No file type provided")
@@ -103,6 +106,12 @@ async def save(self, model, path=""):
103106
if "content" not in model and model["type"] != "directory":
104107
raise web.HTTPError(400, "No file content provided")
105108

109+
os_path = self._get_os_path(path)
110+
if chunk == -1:
111+
self.log.debug(f"Saving last chunk of file {os_path}")
112+
else:
113+
self.log.debug(f"Saving chunk {chunk} of file {os_path}")
114+
106115
try:
107116
if chunk == 1:
108117
await super(AsyncLargeFileManager, self)._save_file(

0 commit comments

Comments
 (0)