1. zikzakmedia
  2. hgnested

Commits

Cédric Krier  committed 8977c74

Add cache on nested property of local repo

  • Participants
  • Parent commits 529ed7c
  • Branches default

Comments (0)

Files changed (1)

File hgnested/__init__.py

View file
  • Ignore whitespace
 
 __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