speed up find method

This commit is contained in:
Richard O'Dwyer 2019-10-31 21:38:04 +00:00
parent 5bef10b4cb
commit 5ec9e78c42

View file

@ -261,7 +261,7 @@ class Mega(object):
shared_keys[s_item['u']][s_item['h']] = ok_dict[s_item['h']] shared_keys[s_item['u']][s_item['h']] = ok_dict[s_item['h']]
self.shared_keys = shared_keys self.shared_keys = shared_keys
def find_path_descriptor(self, path): def find_path_descriptor(self, path, files=()):
""" """
Find descriptor of folder inside a path. i.e.: folder1/folder2/folder3 Find descriptor of folder inside a path. i.e.: folder1/folder2/folder3
Params: Params:
@ -271,7 +271,7 @@ class Mega(object):
""" """
paths = path.split('/') paths = path.split('/')
files = self.get_files() files = files or self.get_files()
parent_desc = self.root_id parent_desc = self.root_id
found = False found = False
for foldername in paths: for foldername in paths:
@ -304,7 +304,9 @@ class Mega(object):
for file in list(files.items()): for file in list(files.items()):
parent_node_id = None parent_node_id = None
if parent_dir_name: if parent_dir_name:
parent_node_id = self.find_path_descriptor(parent_dir_name) parent_node_id = self.find_path_descriptor(
parent_dir_name, files=files
)
if ( if (
filename and parent_node_id and filename and parent_node_id and
file[1]['a'] and file[1]['a']['n'] == filename and file[1]['a'] and file[1]['a']['n'] == filename and