perf: warm the cache after all transactions
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Mon, 01 May 2017 08:14:00 +0200
changeset 2297 32cdcf493567
parent 2296 d6584ce58030
child 2298 8199204274f0
perf: warm the cache after all transactions This is the simplest way to ensure the data are up to date.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Mon May 01 08:13:24 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Mon May 01 08:14:00 2017 +0200
@@ -318,4 +318,25 @@
             if 'obsstore' in vars(self):
                 self.obsstore.obscache.clear()
 
+        def transaction(self, *args, **kwargs):
+            tr = super(obscacherepo, self).transaction(*args, **kwargs)
+            reporef = weakref.ref(self)
+
+            def _warmcache(tr):
+                repo = reporef()
+                if repo is None:
+                    return
+                if 'obsstore' in vars(self):
+                    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 saving
+                    # logic.
+                    self.obsstore.obscache.update(repo)
+                    self.obsstore.obscache.save(repo)
+
+            tr.addpostclose('warmcache-obscache', _warmcache)
+            return tr
+
     repo.__class__ = obscacherepo