diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-06-30 22:17:22 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-06-30 22:17:22 +1200 |
commit | 13b16830e556802f28cbbad98b1db6a94a57c154 (patch) | |
tree | 9c1830aa0d771b5b7291dbf74b2419e7756c5710 | |
parent | 04c32e67e8e0da890286896eabd158d10244e9c7 (diff) | |
download | obnam-13b16830e556802f28cbbad98b1db6a94a57c154.tar.gz |
Speed up adding of newly created file to parent.
No need to do listdir to lookup, we can just lookup
using key.
-rw-r--r-- | obnamlib/store.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/obnamlib/store.py b/obnamlib/store.py index 13f68d68..00cb94f0 100644 --- a/obnamlib/store.py +++ b/obnamlib/store.py @@ -387,10 +387,13 @@ class GenerationStore(StoreTree): parent = os.path.dirname(filename) if parent != filename: # root dir is its own parent basename = os.path.basename(filename) - genid = self.get_generation_id(self.curgen) - if basename not in self.listdir(genid, parent): - subkey = self.hash_name(filename) - key = self.key(parent, self.DIR_CONTENTS, subkey) + subkey = self.hash_name(filename) + key = self.key(parent, self.DIR_CONTENTS, subkey) + # We could just insert, but that would cause unnecessary + # churn in the tree if nothing changes. + try: + self.curgen.lookup(key) + except KeyError: self.curgen.insert(key, basename) def get_metadata(self, genid, filename): |