Patchwork [1,of,2] hgweb: always compute all entries and latestentry in changelog

login
register
mail settings
Submitter Alexander Plavin
Date Sept. 18, 2013, 6:03 p.m.
Message ID <cb1c62872a8aa8f03a03.1379527433@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2517/
State Accepted
Commit ab5442f45441b055650e90aa13167ff47df66161
Headers show

Comments

Alexander Plavin - Sept. 18, 2013, 6:03 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1378459857 -14400
#      Fri Sep 06 13:30:57 2013 +0400
# Node ID cb1c62872a8aa8f03a0353d6432614a922aa786c
# Parent  305568814dbd7e196d116c07e2939db917a32e48
hgweb: always compute all entries and latestentry in changelog

Get the whole list of entries before rendering instead of using lazy evaluation.
This doesn't affect the performance for usual case when the entries are shown
anyway. When both entries and latestentry are used, this performs unnoticeably
faster, and for pages which use only latestentry (quite uncommon case) it
would be a bit slower.
This change will make it possible to get the first entry of the next page easily
without computing the list twice.

Patch

diff -r 305568814dbd -r cb1c62872a8a mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py	Fri Sep 06 13:30:57 2013 +0400
+++ b/mercurial/hgweb/webcommands.py	Fri Sep 06 13:30:57 2013 +0400
@@ -275,12 +275,10 @@ 
     else:
         ctx = web.repo['tip']
 
-    def changelist(latestonly):
+    def changelist():
         revs = []
         if pos != -1:
             revs = web.repo.changelog.revs(pos, 0)
-        if latestonly:
-            revs = (revs.next(),)
         curcount = 0
         for i in revs:
             ctx = web.repo[i]
@@ -325,10 +323,13 @@ 
 
     changenav = webutil.revnav(web.repo).gen(pos, revcount, count)
 
+    entries = list(changelist())
+    latestentry = entries[:1]
+
     return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                 node=ctx.hex(), rev=pos, changesets=count,
-                entries=lambda **x: changelist(latestonly=False),
-                latestentry=lambda **x: changelist(latestonly=True),
+                entries=entries,
+                latestentry=latestentry,
                 archives=web.archivelist("tip"), revcount=revcount,
                 morevars=morevars, lessvars=lessvars, query=query)