pushlog: make repo.pushlog a cached property (
bug 1303904); r?glob
Currently, repo.pushlog creates a new pushlog instance on every
access. This creates overhead and prevents some forms of caching.
The "repofilecache" decorator caches the property value, but only
if the underlying cache hasn't been invalidated by a repo change.
This allows the same pushlog instance to be returned as long as no
updates have occurred.
This is the easiest way to implement a cache of the pushlog instance
without having to consider implications of reusing mutated instances.
MozReview-Commit-ID: D3TZbkpJ7iJ
--- a/hgext/pushlog/__init__.py
+++ b/hgext/pushlog/__init__.py
@@ -14,16 +14,17 @@ import time
from mercurial.node import bin, hex
from mercurial import (
cmdutil,
encoding,
error,
exchange,
extensions,
+ localrepo,
registrar,
revset,
templatekw,
util,
wireproto,
)
from mercurial.hgweb import (
webutil,
@@ -759,17 +760,20 @@ def extsetup(ui):
def reposetup(ui, repo):
if not repo.local():
return
ui.setconfig('hooks', 'pretxnchangegroup.pushlog', pretxnchangegrouphook, 'pushlog')
class pushlogrepo(repo.__class__):
- @property
+ # We /may/ be able to turn this into a property cache without the
+ # filesystem check. But the filesystem check is safer in case pushlog
+ # mutation invalidates cached state on type instances.
+ @localrepo.repofilecache('pushlog2.db')
def pushlog(self):
return pushlog(self)
def destroyed(self):
super(pushlogrepo, self).destroyed()
self.pushlog.handledestroyed()
repo.__class__ = pushlogrepo