Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove B2FileList's unused file cache #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions b2blaze/models/b2_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ def hide(self):
response = self.connector.make_request(path=path, method='post', params=params)
if response.status_code == 200:
self.deleted = True
# Delete from parent list if exists
self.parent_list._files_by_name.pop(self.file_name)
self.parent_list._files_by_id.pop(self.file_id)
else:
raise B2Exception.parse(response)

Expand Down
18 changes: 4 additions & 14 deletions b2blaze/models/file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def __init__(self, connector, bucket):
"""
self.connector = connector
self.bucket = bucket
self._files_by_name = {}
self._files_by_id = {}

def all(self, include_hidden=False, limit=None):
""" Return an updated list of all files.
Expand All @@ -33,7 +31,7 @@ def all(self, include_hidden=False, limit=None):

"""
if not include_hidden:
return self._update_files_list(retrieve=True, limit=limit)
return self._retrieve_file_list(limit=limit)
else:
results = self.all_file_versions(limit=limit)
versions = results['file_versions']
Expand Down Expand Up @@ -61,38 +59,32 @@ def delete_all(self, confirm=False):
return []


def _update_files_list(self, retrieve=False, limit=None):
def _retrieve_file_list(self, limit=10000):
""" Retrieve list of all files in bucket
Parameters:
limit: (int) Max number of file results, default 10000
retrieve: (bool) Refresh local store. (default: false)
"""
path = API.list_all_files
files = []
new_files_to_retrieve = True
params = {
'bucketId': self.bucket.bucket_id,
'maxFileCount': limit or 10000
'maxFileCount': limit,
}
while new_files_to_retrieve:
response = self.connector.make_request(path=path, method='post', params=params)
if response.status_code == 200:
files_json = response.json()
self._files_by_name = {}
self._files_by_id = {}
for file_json in files_json['files']:
new_file = B2File(connector=self.connector, parent_list=self, **file_json)
files.append(new_file)
self._files_by_name[file_json['fileName']] = new_file
self._files_by_id[file_json['fileId']] = new_file
if files_json['nextFileName'] is None:
new_files_to_retrieve = False
else:
params['startFileName'] = files_json['nextFileName']
else:
raise B2Exception.parse(response)
if retrieve:
return files
return files


def get(self, file_name=None, file_id=None):
Expand Down Expand Up @@ -250,8 +242,6 @@ def upload(self, contents, file_name, mime_content_type=None, content_length=Non
content_length=content_length, progress_listener=progress_listener)
if upload_response.status_code == 200:
new_file = B2File(connector=self.connector, parent_list=self, **upload_response.json())
# Update file list after upload
self._update_files_list()
return new_file
else:
raise B2Exception.parse(upload_response)
Expand Down