caches: add a 'auto' option for obshashrange cache warming
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 05 Jan 2018 04:26:59 +0100
changeset 3368 7310f3ef6dee
parent 3367 c26dc74b828d
child 3369 c7fbb79cd366
caches: add a 'auto' option for obshashrange cache warming This option will only warm the cache when used as a server.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/utility.py
--- a/hgext3rd/evolve/__init__.py	Fri Jan 05 04:26:51 2018 +0100
+++ b/hgext3rd/evolve/__init__.py	Fri Jan 05 04:26:59 2018 +0100
@@ -72,15 +72,17 @@
   # (needed on both client and server)
   obshashrange = yes
 
-  # avoid cache warming after transaction
-  # (recommended 'off' for developer repositories)
-  # (recommended 'yes' for server (default))
-  obshashrange.warm-cache = no
+  # control cache warming at the end of transaction
+  #   yes:  warm all caches at the end of each transaction,
+  #   off:  warm no caches at the end of transaction,
+  #   auto: warm cache at the end of server side transaction.
+  obshashrange.warm-cache = 'auto'
 
-The initial cache warming is currently a bit slow. To make sure it is build you
-can run the following commands in your repository::
+The initial cache warming might be a bit slow. To make sure it is build you
+can run one of the following commands in your repository::
 
-    $ hg debugobshashrange --rev 'head()
+    $ hg debugupdatecache # mercurial 4.3 and above
+    $ hg debugobshashrange --rev 'head() # mercurial 4.2 and below
 
 It is recommended to enable the blackbox extension. It gathers useful data about
 the experiment. It is shipped with Mercurial so no extra install is needed::
--- a/hgext3rd/evolve/utility.py	Fri Jan 05 04:26:51 2018 +0100
+++ b/hgext3rd/evolve/utility.py	Fri Jan 05 04:26:59 2018 +0100
@@ -39,7 +39,16 @@
 
 def shouldwarmcache(repo, tr):
     configbool = repo.ui.configbool
-    warm = configbool('experimental', 'obshashrange.warm-cache', True)
+    config = repo.ui.config
+    desc = getattr(tr, 'desc', '')
+
+    autocase = tr is None or desc.startswith('push') or desc.startswith('serve')
+    autocache = config('experimental', 'obshashrange.warm-cache',
+                       False) == 'auto'
+    if autocache:
+        warm = autocase
+    else:
+        warm = configbool('experimental', 'obshashrange.warm-cache', True)
 
     if not configbool('experimental', 'obshashrange', False):
         return False