changeset 2297:32cdcf493567

perf: warm the cache after all transactions This is the simplest way to ensure the data are up to date.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Mon, 01 May 2017 08:14:00 +0200
parents d6584ce58030
children 8199204274f0
files hgext3rd/evolve/obscache.py
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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