<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 23, 2016 at 3:23 PM, Pierre-Yves David <span dir="ltr"><<a href="mailto:pierre-yves.david@ens-lyon.org" target="_blank">pierre-yves.david@ens-lyon.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<br>
On 09/22/2016 08:21 PM, Matt Mackall wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
# HG changeset patch<br>
# User Matt Mackall <<a href="mailto:mpm@selenic.com" target="_blank">mpm@selenic.com</a>><br>
# Date 1474294391 18000<br>
#      Mon Sep 19 09:13:11 2016 -0500<br>
# Node ID 133b35066bef5d9c31d13c4f0b2e4a<wbr>50d1ceae87<br>
# Parent  9c8847df32a0c5045e60aded2e03a9<wbr>c97507f909<br>
extdata: add basic caching<br>
<br>
Sources used for log templating will be queried for every changeset<br>
printed. So we need a cache. We attach the cache to the repo object to<br>
give it a bounded lifetime.<br>
<br>
diff -r 9c8847df32a0 -r 133b35066bef mercurial/scmutil.py<br>
--- a/mercurial/scmutil.py      Mon Sep 19 09:05:00 2016 -0500<br>
+++ b/mercurial/scmutil.py      Mon Sep 19 09:13:11 2016 -0500<br>
@@ -1453,6 +1453,14 @@<br>
         raise error.Abort(_("extdata doesn't support parameters yet"),<br>
                           hint=_("use double % for escaping"))<br>
<br>
+    # we cache external data sources for the lifetime of a repo object<br>
+    # users like log templates may consult a data source very frequently<br>
+    if not util.safehasattr(repo, "_extdatacache"):<br>
+        repo._extdatacache = {}<br>
+    cache = repo._extdatacache<br>
+    if spec in cache:<br>
+        return cache[spec]<br>
+<br>
</blockquote>
<br></div></div>
While caching is obviously necessary, repo-life caching is likely to provide bogus result with long lived process like chg or the command server. We probably needs more aggressive invalidation. What about caching the data for each "commands" as a start.<br>
<br>
(that cache question is vast, because in some case we probably want to have a very strong caching with on disk version, but that is adventure for another castle imho)<br><br></blockquote><div><br></div><div>We definitely need a more robust caching mechanism because this definitely breaks hgweb, which uses hg.cachedlocalrepo to represent cached repos between HTTP requests and currently only knows to invalidate if {changelog, phaseroots, obsstore, bookmarks} files change.<br><br>In the current state of this patch, a repo._extdatacache entry will persist for the lifetime of a hgweb process until the repo is written to. That could be hours. At the very least you'll probably want to teach cachedlocalrepo.fetch() to clear repo._extdatacache.<br></div></div></div></div>