obshashrange: update the cache updating logic
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 21 Dec 2017 04:39:45 +0100
changeset 3354 32e7ceaf1d82
parent 3353 4635cef9624c
child 3355 c261eece1eab
obshashrange: update the cache updating logic Use the more modern option when available. (Same as the other caches).
hgext3rd/evolve/obsdiscovery.py
tests/test-discovery-obshashrange.t
--- a/hgext3rd/evolve/obsdiscovery.py	Thu Dec 21 04:24:37 2017 +0100
+++ b/hgext3rd/evolve/obsdiscovery.py	Thu Dec 21 04:39:45 2017 +0100
@@ -580,30 +580,30 @@
                 self.obsstore.rangeobshashcache.clear()
             super(obshashrepo, self).destroyed()
 
-        def transaction(self, *args, **kwargs):
-            tr = super(obshashrepo, self).transaction(*args, **kwargs)
-            reporef = weakref.ref(self)
+        if util.safehasattr(repo, 'updatecaches'):
+            @localrepo.unfilteredmethod
+            def updatecaches(self, tr=None):
+                if utility.shouldwarmcache(self):
+                    self.obsstore.rangeobshashcache.update(self)
+                    self.obsstore.rangeobshashcache.save(self)
+                super(obshashrepo, self).updatecaches(tr)
 
-            def _warmcache(tr):
-                repo = reporef()
-                if repo is None:
-                    return
-                hasobshashrange = _useobshashrange(repo)
-                hascachewarm = repo.ui.configbool('experimental',
-                                                  'obshashrange.warm-cache',
-                                                  True)
-                if not (hasobshashrange and hascachewarm):
-                    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)
+        else:
+            def transaction(self, *args, **kwargs):
+                tr = super(obshashrepo, self).transaction(*args, **kwargs)
+                reporef = weakref.ref(self)
 
-            tr.addpostclose('warmcache-20-obscacherange', _warmcache)
-            return tr
+                def _warmcache(tr):
+                    repo = reporef()
+                    if repo is None:
+                        return
+                    repo = repo.unfiltered()
+                    repo.obsstore.rangeobshashcache.update(repo)
+                    repo.obsstore.rangeobshashcache.save(repo)
+
+                if utility.shouldwarmcache(self):
+                    tr.addpostclose('warmcache-20obshashrange', _warmcache)
+                return tr
 
     repo.__class__ = obshashrepo
 
--- a/tests/test-discovery-obshashrange.t	Thu Dec 21 04:24:37 2017 +0100
+++ b/tests/test-discovery-obshashrange.t	Thu Dec 21 04:39:45 2017 +0100
@@ -592,10 +592,12 @@
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> 1 incoming changes - new heads: 4de32a90b66c (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> pull exited 0 after *.?? seconds (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> rollback (glob)
-  * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> strip detected, evo-ext-stablerange-mergepoint cache reset (glob)
+  * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> strip detected, evo-ext-obshashrange cache reset (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> strip detected, evo-ext-depthcache cache reset (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> updated evo-ext-depthcache in *.???? seconds (8r) (glob)
+  * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> strip detected, evo-ext-stablerange-mergepoint cache reset (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> updated evo-ext-stablerange-mergepoint in *.???? seconds (8r) (glob)
+  * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> updated evo-ext-obshashrange in *.???? seconds (8r, 12o) (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> strip detected, evo-ext-firstmerge cache reset (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> updated evo-ext-firstmerge in *.???? seconds (8r) (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> strip detected, evo-ext-stablesort cache reset (glob)
@@ -638,8 +640,6 @@
   (run 'hg update' to get a working copy)
   $ hg blackbox
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> debugobshashrange --subranges --rev 'heads(all())' (glob)
-  * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> strip detected, evo-ext-obshashrange cache reset (glob)
-  * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> updated evo-ext-obshashrange in *.???? seconds (8r, 12o) (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> debugobshashrange --subranges --rev 'heads(all())' exited 0 after *.?? seconds (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> pull (glob)
   * @45f8b879de922f6a6e620ba04205730335b6fc7e (*)> obsdiscovery, 0/8 mismatch - 1 obshashrange queries in *.???? seconds (glob)