diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-02-25 08:54:55 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-02-25 08:54:55 +0000 |
commit | 18a5f748c6309f7e986b833a84a93cc792b2120e (patch) | |
tree | 0086cdd64e070ce2e297e240053c74221b6738e9 /obnamlib/plugins/fuse_plugin.py | |
parent | b7512ada93c2de80f3be6374bc7c32643c61940e (diff) | |
download | obnam-18a5f748c6309f7e986b833a84a93cc792b2120e.tar.gz |
Cache chunk sizes for read
Diffstat (limited to 'obnamlib/plugins/fuse_plugin.py')
-rw-r--r-- | obnamlib/plugins/fuse_plugin.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/obnamlib/plugins/fuse_plugin.py b/obnamlib/plugins/fuse_plugin.py index 9ff6eaae..b7540808 100644 --- a/obnamlib/plugins/fuse_plugin.py +++ b/obnamlib/plugins/fuse_plugin.py @@ -149,11 +149,23 @@ class ObnamFuseFile(object): output = [] output_length = 0 chunk_pos_in_file = 0 + size_cache = self.fuse_fs.obnam.chunk_sizes + for chunkid in chunkids: - contents = self.fuse_fs.obnam.repo.get_chunk_content(chunkid) - if chunk_pos_in_file + len(contents) >= offset: + if chunkid in size_cache: + contents = None + size = size_cache[chunkid] + else: + contents = self.fuse_fs.obnam.repo.get_chunk_content(chunkid) + size = len(contents) + size_cache[chunkid] = size + + if chunk_pos_in_file + size >= offset: start = offset - chunk_pos_in_file n = length - output_length + if contents is None: + contents = self.fuse_fs.obnam.repo.get_chunk_content( + chunkid) data = contents[start : n] output.append(data) output_length += len(data) @@ -597,6 +609,11 @@ class MountPlugin(obnamlib.ObnamPlugin): self.app.settings['generation'], self.app.settings['to']) + # For speed, we need to remember how large each chunk is. + # We store it here in the plugin so the cache survives a + # re-open. + self.chunk_sizes = {} + try: ObnamFuseOptParse.obnam = self fuse_fs = ObnamFuse(obnam=self, parser_class=ObnamFuseOptParse) |