summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-07-11 19:58:31 +0300
committerLars Wirzenius <liw@liw.fi>2015-07-11 19:58:31 +0300
commita84b881f4a20be4ed3b65c13d306ec022d40f8de (patch)
treeea9f224a968d7e7de87aa08a9273d22ec48aa281
parentd8f8704d0e2fbf59d03946e8eb5a00e522941059 (diff)
downloadobnam-a84b881f4a20be4ed3b65c13d306ec022d40f8de.tar.gz
Cache lookups of get_directory
-rw-r--r--obnamlib/fmt_ga/tree.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/obnamlib/fmt_ga/tree.py b/obnamlib/fmt_ga/tree.py
index 701842ca..cbe36c22 100644
--- a/obnamlib/fmt_ga/tree.py
+++ b/obnamlib/fmt_ga/tree.py
@@ -18,6 +18,8 @@
import os
+import tracing
+
import obnamlib
@@ -51,21 +53,29 @@ class GATree(object):
def get_directory(self, pathname):
if pathname in self._cache:
+ tracing.trace('cache hit: pathname=%r', pathname)
return self._cache.get(pathname)
+ tracing.trace('cache miss: pathname=%r', pathname)
+
if self._root_dir_id is None:
return None
+ dir_obj = None
if pathname == '/':
- return self._get_dir_obj(self._root_dir_id)
+ dir_obj = self._get_dir_obj(self._root_dir_id)
else:
parent_obj = self._get_containing_dir_obj(pathname)
if parent_obj is not None:
basename = os.path.basename(pathname)
obj_id = parent_obj.get_subdir_object_id(basename)
if obj_id is not None:
- return self._get_dir_obj(obj_id)
- return None # pragma: no cover
+ dir_obj = self._get_dir_obj(obj_id)
+
+ if dir_obj is not None:
+ self._cache.set(pathname, dir_obj)
+
+ return dir_obj
def _get_dir_obj(self, dir_id):
blob = self._blob_store.get_blob(dir_id)
@@ -94,6 +104,9 @@ class GATree(object):
else:
parent_obj = obnamlib.GADirectory()
parent_obj.add_file('.')
+ if not parent_obj.is_mutable():
+ parent_obj = obnamlib.create_gadirectory_from_dict(
+ parent_obj.as_dict())
parent_obj.add_subdir(basename, None)
self.set_directory(parent_path, parent_obj)