Cédric Krier avatar Cédric Krier committed 8977c74

Add cache on nested property of local repo

Comments (0)

Files changed (1)

hgnested/__init__.py

 
 __version__ = '0.2'
 
+_nested_cache = {}
+_nested_refreshinterval = 20
+
 @property
 def _localrepo_nested(self):
     '''Return a list of nested repositories.'''
+    cache = _nested_cache.setdefault(self.root, {
+        'lastrefresh': 0,
+        'nested': None,
+        })
+    if cache['lastrefresh'] + _nested_refreshinterval > time.time():
+        return cache['nested']
     res = {}
     paths = [self.root]
     while paths:
     prefix = len(self.root) + 1
     res = [x[prefix:] or '.' for x in res.itervalues()]
     res.sort()
+    cache['nested'] = res
+    cache['lastrefresh'] = time.time()
     return res
 
 localrepo.localrepository.nested = _localrepo_nested
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.