Re: [PATCH 4 of 4] hgweb: render next pages on /graph incrementally

2017-12-14 Thread Anton Shestakov
On Thu, 14 Dec 2017 21:11:35 +0900
Yuya Nishihara  wrote:

> On Wed, 13 Dec 2017 00:27:49 +0800, Anton Shestakov wrote:
> > # HG changeset patch
> > # User Anton Shestakov 
> > # Date 1512978236 -28800
> > #  Mon Dec 11 15:43:56 2017 +0800
> > # Node ID 865e71e7184410b60e2dd2912407d3884514e437
> > # Parent  79649cbad159b574d85902abc195089af01241cf
> > hgweb: render next pages on /graph incrementally
> > 
> > Previously, when user scrolled down to see the next page on /graph, all 
> > hgweb
> > did was re-render everything that would be visible (by simply incrementing
> > revcount). It was not efficient at all, and this patch makes /graph page 
> > behave
> > similarly to the regular /log: every new page only consists of new 
> > changesets,
> > no duplication, and only jsdata is based on the full set of changesets 
> > required
> > to build accurate graph.
> > 
> > This is achieved by adding "?graphtop=" to the next page URL template,
> > effectively remembering where the graph started, and using that value to 
> > create
> > the new `tree` that covers the whole visible graph. That variable is then 
> > used
> > to produce jsdata for redrawing graph client-side.
> 
> Can you update the docstring of graph()?

Right, I'll send a follow-up soon. Thanks for reviewing!
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 4 of 4] hgweb: render next pages on /graph incrementally

2017-12-14 Thread Yuya Nishihara
On Wed, 13 Dec 2017 00:27:49 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov 
> # Date 1512978236 -28800
> #  Mon Dec 11 15:43:56 2017 +0800
> # Node ID 865e71e7184410b60e2dd2912407d3884514e437
> # Parent  79649cbad159b574d85902abc195089af01241cf
> hgweb: render next pages on /graph incrementally
> 
> Previously, when user scrolled down to see the next page on /graph, all hgweb
> did was re-render everything that would be visible (by simply incrementing
> revcount). It was not efficient at all, and this patch makes /graph page 
> behave
> similarly to the regular /log: every new page only consists of new changesets,
> no duplication, and only jsdata is based on the full set of changesets 
> required
> to build accurate graph.
> 
> This is achieved by adding "?graphtop=" to the next page URL template,
> effectively remembering where the graph started, and using that value to 
> create
> the new `tree` that covers the whole visible graph. That variable is then used
> to produce jsdata for redrawing graph client-side.

Can you update the docstring of graph()?
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 4 of 4] hgweb: render next pages on /graph incrementally

2017-12-12 Thread Anton Shestakov
# HG changeset patch
# User Anton Shestakov 
# Date 1512978236 -28800
#  Mon Dec 11 15:43:56 2017 +0800
# Node ID 865e71e7184410b60e2dd2912407d3884514e437
# Parent  79649cbad159b574d85902abc195089af01241cf
hgweb: render next pages on /graph incrementally

Previously, when user scrolled down to see the next page on /graph, all hgweb
did was re-render everything that would be visible (by simply incrementing
revcount). It was not efficient at all, and this patch makes /graph page behave
similarly to the regular /log: every new page only consists of new changesets,
no duplication, and only jsdata is based on the full set of changesets required
to build accurate graph.

This is achieved by adding "?graphtop=" to the next page URL template,
effectively remembering where the graph started, and using that value to create
the new `tree` that covers the whole visible graph. That variable is then used
to produce jsdata for redrawing graph client-side.

nextentry is used for the same purpose as on /log page (to format the next page
URL), but it's not a part of the graph.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -1207,6 +1207,10 @@ def graph(web, req, tmpl):
 morevars = copy.copy(tmpl.defaults['sessionvars'])
 morevars['revcount'] = revcount * 2
 
+graphtop = req.form.get('graphtop', [ctx.hex()])[0]
+graphvars = copy.copy(tmpl.defaults['sessionvars'])
+graphvars['graphtop'] = graphtop
+
 count = len(web.repo)
 pos = rev
 
@@ -1215,14 +1219,22 @@ def graph(web, req, tmpl):
 changenav = webutil.revnav(web.repo).gen(pos, revcount, count)
 
 tree = []
+nextentry = []
+lastrev = 0
 if pos != -1:
 allrevs = web.repo.changelog.revs(pos, 0)
 revs = []
 for i in allrevs:
 revs.append(i)
-if len(revs) >= revcount:
+if len(revs) >= revcount + 1:
 break
 
+if len(revs) > revcount:
+nextentry = [webutil.commonentry(web.repo, web.repo[revs[-1]])]
+revs = revs[:-1]
+
+lastrev = revs[-1]
+
 # We have to feed a baseset to dagwalker as it is expecting smartset
 # object. This does not have a big impact on hgweb performance itself
 # since hgweb graphing code is not itself lazy yet.
@@ -1231,11 +1243,21 @@ def graph(web, req, tmpl):
 tree = list(item for item in graphmod.colored(dag, web.repo)
 if item[1] == graphmod.CHANGESET)
 
+def fulltree():
+pos = web.repo[graphtop].rev()
+tree = []
+if pos != -1:
+revs = web.repo.changelog.revs(pos, lastrev)
+dag = graphmod.dagwalker(web.repo, smartset.baseset(revs))
+tree = list(item for item in graphmod.colored(dag, web.repo)
+if item[1] == graphmod.CHANGESET)
+return tree
+
 def jsdata():
 return [{'node': pycompat.bytestr(ctx),
  'vertex': vtx,
  'edges': edges}
-for (id, type, ctx, vtx, edges) in tree]
+for (id, type, ctx, vtx, edges) in fulltree()]
 
 def nodes():
 for row, (id, type, ctx, vtx, edges) in enumerate(tree):
@@ -1260,9 +1282,11 @@ def graph(web, req, tmpl):
 return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount,
 uprev=uprev,
 lessvars=lessvars, morevars=morevars, downrev=downrev,
+graphvars=graphvars,
 rows=rows,
 bg_height=bg_height,
 changesets=count,
+nextentry=nextentry,
 jsdata=lambda **x: jsdata(),
 nodes=lambda **x: nodes(),
 node=ctx.hex(), changenav=changenav)
diff --git a/mercurial/templates/gitweb/graph.tmpl 
b/mercurial/templates/gitweb/graph.tmpl
--- a/mercurial/templates/gitweb/graph.tmpl
+++ b/mercurial/templates/gitweb/graph.tmpl
@@ -67,9 +67,12 @@ graph.render(data);