提交 19976b0c authored 作者: Frederic's avatar Frederic

Make less file system access to the cache.

This speed up the loading and the refresh. The refresh with a local cache with ~650 element went from 0.01s to 0.001s.
上级 f3f97d77
...@@ -640,13 +640,16 @@ class ModuleCache(object): ...@@ -640,13 +640,16 @@ class ModuleCache(object):
time_now = time.time() time_now = time.time()
# Go through directories in alphabetical order to ensure consistent # Go through directories in alphabetical order to ensure consistent
# behavior. # behavior.
root_dirs_files = sorted(os.walk(self.dirname), subdirs = sorted(os.listdir(self.dirname))
key=operator.itemgetter(0)) for root in subdirs:
for root, dirs, files in root_dirs_files: root = os.path.join(self.dirname, root)
key_pkl = os.path.join(root, 'key.pkl') key_pkl = os.path.join(root, 'key.pkl')
if key_pkl in self.loaded_key_pkl: if key_pkl in self.loaded_key_pkl:
continue continue
elif 'delete.me' in files or not files: if not os.path.isdir(root):
continue
files = os.listdir(root)
if 'delete.me' in files or not files:
_rmtree(root, ignore_nocleanup=True, _rmtree(root, ignore_nocleanup=True,
msg="delete.me found in dir") msg="delete.me found in dir")
elif 'key.pkl' in files: elif 'key.pkl' in files:
...@@ -814,8 +817,7 @@ class ModuleCache(object): ...@@ -814,8 +817,7 @@ class ModuleCache(object):
# We do nothing here. # We do nothing here.
# Clean up the name space to prevent bug. # Clean up the name space to prevent bug.
if root_dirs_files: del root, files, subdirs
del root, dirs, files
# Remove entries that are not in the filesystem. # Remove entries that are not in the filesystem.
items_copy = list(self.module_hash_to_key_data.iteritems()) items_copy = list(self.module_hash_to_key_data.iteritems())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论