[PATCH] hgwebdir: cache hgweb instances (and their repos) between calls
Sune Foldager
cryo at cyanite.org
Tue May 24 06:01:07 CDT 2011
# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1306234857 -7200
# Node ID 70b4f148d838bbd8b2da7540b135cc092ef98250
# Parent 25137d99a5ed215f302ffc1793590bdbdb437b55
hgwebdir: cache hgweb instances (and their repos) between calls
diff -r 25137d99a5ed -r 70b4f148d838 mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py Mon May 23 22:49:10 2011 -0500
+++ b/mercurial/hgweb/hgwebdir_mod.py Tue May 24 13:00:57 2011 +0200
@@ -59,6 +59,7 @@
self.baseui = baseui
self.lastrefresh = 0
self.motd = None
+ self.hgwebs = {}
self.refresh()
def refresh(self):
@@ -96,6 +97,8 @@
name = name[len(prefix):]
repos.append((name.lstrip('/'), repo))
+ repopaths = set(repo[1] for repo in repos)
+ self.hgwebs = dict((p, self.hgwebs.get(p)) for p in repopaths)
self.repos = repos
self.ui = u
encoding.encoding = self.ui.config('web', 'encoding',
@@ -174,8 +177,12 @@
if real:
req.env['REPO_NAME'] = virtualrepo
try:
- repo = hg.repository(self.ui, real)
- return hgweb(repo).run_wsgi(req)
+ hgwebinst = self.hgwebs.get(real)
+ if not hgwebinst:
+ repo = hg.repository(self.ui, real)
+ hgwebinst = hgweb(repo)
+ self.hgwebs[real] = hgwebinst
+ return hgwebinst.run_wsgi(req)
except IOError, inst:
msg = inst.strerror
raise ErrorResponse(HTTP_SERVER_ERROR, msg)
More information about the Mercurial-devel
mailing list