pushlog: make repo.pushlog a cached property (bug 1303904); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Mon, 19 Jun 2017 11:35:21 -0700
changeset 11234 442f057545cd56c529841eccc103f55cae50acf1
parent 11233 d9d1f05f3062383ba367e28a91ae5f692f223068
child 11235 5cc88b2d2b8cf33d341780678114240df8331397
push id1708
push usergszorc@mozilla.com
push dateMon, 19 Jun 2017 18:36:36 +0000
reviewersglob
bugs1303904
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
hgext/pushlog/__init__.py
--- 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