diff --git a/b2blaze/models/b2_file.py b/b2blaze/models/b2_file.py index 320ca34..31b7933 100644 --- a/b2blaze/models/b2_file.py +++ b/b2blaze/models/b2_file.py @@ -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) diff --git a/b2blaze/models/file_list.py b/b2blaze/models/file_list.py index ecf8c1e..e6e2854 100644 --- a/b2blaze/models/file_list.py +++ b/b2blaze/models/file_list.py @@ -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. @@ -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'] @@ -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): @@ -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)