# HG changeset patch # User Pierre-Yves David # Date 1493619240 -7200 # Node ID 32cdcf493567c55bc8f412af0fc23af3b1733ad1 # Parent d6584ce580309b62715d8c239cdeb3a634b75398 perf: warm the cache after all transactions This is the simplest way to ensure the data are up to date. diff -r d6584ce58030 -r 32cdcf493567 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