diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-07-10 10:47:25 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-07-10 10:47:25 +1200 |
commit | b9857ea68dcf3ad940708d65b390162be035db3d (patch) | |
tree | f452911ab8fca82a9f3584ece00025f7e9881ebc | |
parent | 89288ce0fe5c56eb0476a1518a9f06fa375225aa (diff) | |
download | obnam-b9857ea68dcf3ad940708d65b390162be035db3d.tar.gz |
Cache results of find_generation, for speed.
-rw-r--r-- | obnamlib/store.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/obnamlib/store.py b/obnamlib/store.py index 903c0044..8e6226b5 100644 --- a/obnamlib/store.py +++ b/obnamlib/store.py @@ -263,6 +263,7 @@ class GenerationStore(StoreTree): StoreTree.__init__(self, fs, hostname, key_bytes, node_size, upload_queue_size) self.curgen = None + self.known_generations = dict() def hash_name(self, filename): '''Return hash of filename suitable for use as main key.''' @@ -325,9 +326,13 @@ class GenerationStore(StoreTree): self.forest.commit() def find_generation(self, genid): + if genid in self.known_generations: # pragma: no cover + return self.known_generations[genid] + key = self.genkey(self.GEN_META_ID) for t in self.forest.trees: if self._lookup_int(t, key) == genid: + self.known_generations[genid] = t return t raise KeyError('Unknown generation %s' % genid) # pragma: no cover |