Skip to content

Commit

Permalink
Fix performance problems with large directories
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarkovtsev committed Aug 24, 2016
1 parent d0b9cca commit 04a592c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions jgscm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
from itertools import islice
import os
import uuid

Expand Down Expand Up @@ -125,7 +126,7 @@ def list_checkpoints(self, path):
checkpoints = [{
"id": os.path.splitext(file.path)[0][-36:],
"last_modified": file.updated,
} for file in it]
} for file in islice(it, self.parent.max_list_size)]
except NotFound:
return []
checkpoints.sort(key=lambda c: c["last_modified"], reverse=True)
Expand Down Expand Up @@ -161,7 +162,7 @@ class GoogleStorageContentManager(ContentsManager):
"for authorization. If you do not set this parameter, "
"gcloud will be OK if the default project exists."
)
max_list_size = Int(1024, config=True, help="list_blobs() limit")
max_list_size = Int(128, config=True, help="list_blobs() limit")
cache_buckets = Bool(True, config=True,
help="Value indicating whether to cache the bucket "
"objects for faster operations.")
Expand Down Expand Up @@ -340,7 +341,7 @@ def delete_file(self, path):
return
it = bucket.list_blobs(prefix=bucket_path, delimiter="/",
max_results=self.max_list_size)
files = list(it)
files = list(islice(it, self.max_list_size))
folders = it.prefixes
bucket.delete_blobs(files)
for folder in folders:
Expand All @@ -367,7 +368,7 @@ def rename_file(self, old_path, new_path):
new_bucket_path += "/"
it = old_bucket.list_blobs(prefix=old_bucket_path, delimiter="/",
max_results=self.max_list_size)
old_blobs = list(it)
old_blobs = list(islice(it, self.max_list_size))
folders = it.prefixes
for ob in old_blobs:
old_bucket.rename_blob(
Expand All @@ -388,7 +389,7 @@ def rename_file(self, old_path, new_path):
new_bucket_path += "/"
it = old_bucket.list_blobs(prefix=old_bucket_path, delimiter="/",
max_results=self.max_list_size)
old_blobs = list(it)
old_blobs = list(islice(it, self.max_list_size))
folders = it.prefixes
for ob in old_blobs:
old_bucket.copy_blob(ob, new_bucket, new_bucket_path +
Expand Down Expand Up @@ -553,7 +554,7 @@ def _fetch(self, path, content=True):
it = bucket.list_blobs(prefix=bucket_path, delimiter="/",
max_results=max_list_size)
try:
files = list(it)
files = list(islice(it, max_list_size))
except BrokenPipeError:
return self._fetch(path, content)
except NotFound:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
name="jgscm",
description="Jupyter Google Cloud Storage ContentsManager",
version="0.1.4",
version="0.1.5",
license="MIT",
author="Vadim Markovtsev",
author_email="[email protected]",
Expand Down

0 comments on commit 04a592c

Please sign in to comment.