obshashrange: "update" the cache on each transaction close
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 12 May 2017 21:20:02 +0200
changeset 2364 9b68e65fad4f
parent 2363 2ceb122fcc33
child 2365 4b8b7fd135eb
obshashrange: "update" the cache on each transaction close Right now the "update" does not really file the cache, but it will detect invalid situation and clean them.
hgext3rd/evolve/obsdiscovery.py
--- a/hgext3rd/evolve/obsdiscovery.py	Fri May 12 20:52:19 2017 +0200
+++ b/hgext3rd/evolve/obsdiscovery.py	Fri May 12 21:20:02 2017 +0200
@@ -596,6 +596,27 @@
                 self.obsstore.rangeobshashcache.clear()
             super(obshashrepo, self).destroyed()
 
+        def transaction(self, *args, **kwargs):
+            tr = super(obshashrepo, self).transaction(*args, **kwargs)
+            reporef = weakref.ref(self)
+
+            def _warmcache(tr):
+                repo = reporef()
+                if repo is None:
+                    return
+                if not repo.ui.configbool('experimental', 'obshashrange', False):
+                    return
+                repo = repo.unfiltered()
+                # As pointed in 'obscache.update', we could have the changelog
+                # and the obsstore in charge of updating the cache when new
+                # items goes it. The tranaction logic would then only be
+                # involved for the 'pending' and final writing on disk.
+                self.obsstore.rangeobshashcache.update(repo)
+                self.obsstore.rangeobshashcache.save(repo)
+
+            tr.addpostclose('warmcache-obscacherange', _warmcache)
+            return tr
+
     repo.__class__ = obshashrepo
 
 ### wire protocol commands