From 572ce2d6274d536fb8b3af97e6c27893fd612854 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 11 Nov 2020 21:58:34 -0800 Subject: [PATCH] Don't fetch trash node id until needed. Fetching trash's ID performs a call to get_files which can be somewhat slow. Some use cases do not require ever calling get_files. --- src/mega/mega.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mega/mega.py b/src/mega/mega.py index d842783..256cf48 100644 --- a/src/mega/mega.py +++ b/src/mega/mega.py @@ -35,7 +35,7 @@ class Mega: self.sid = None self.sequence_num = random.randint(0, 0xFFFFFFFF) self.request_id = crypto.make_id(10) - self._trash_folder_node_id = None + self._cached_trash_folder_node_id = None self.shared_keys = {} self.requests_session = requests.Session() @@ -110,12 +110,17 @@ class Mega: resp = self._api_request(request) return resp + @property + def _trash_folder_node_id(self): + if self._cached_trash_folder_node_id is None: + self._cached_trash_folder_node_id = self.get_node_by_type(NODE_TYPE_TRASH)[0] + return self._cached_trash_folder_node_id + def login(self, email=None, password=None): if email: self._login_user(email, password) else: self.login_anonymous() - self._trash_folder_node_id = self.get_node_by_type(NODE_TYPE_TRASH)[0] logger.info('Login complete') return self