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=<node>" 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.
This commit is contained in:
Anton Shestakov 2017-12-11 15:43:56 +08:00
parent 820b447ff6
commit 7f5566e502
7 changed files with 56 additions and 18 deletions

View File

@ -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)

View File

@ -67,9 +67,12 @@ graph.render(data);
<script type="text/javascript"{if(nonce, ' nonce="{nonce}"')}>
ajaxScrollInit(
'{url|urlescape}graph/{rev}?revcount=%next%&style={style}',
{revcount}+60,
function (htmlText, previousVal) \{ return previousVal + 60; },
'{url|urlescape}graph/%next%{graphvars%urlparameter}',
'{nextentry%"{node}"}', <!-- NEXTHASH
function (htmlText, previousVal) \{
var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
return m ? m[1] : null;
},
'#wrapper',
'<div class="%class%" style="text-align: center;">%text%</div>',
'graph'

View File

@ -61,9 +61,12 @@
<script type="text/javascript"{if(nonce, ' nonce="{nonce}"')}>
ajaxScrollInit(
'{url|urlescape}graph/{rev}?revcount=%next%&style={style}',
{revcount}+60,
function (htmlText, previousVal) \{ return previousVal + 60; },
'{url|urlescape}graph/%next%{graphvars%urlparameter}',
'{nextentry%"{node}"}', <!-- NEXTHASH
function (htmlText, previousVal) \{
var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
return m ? m[1] : null;
},
'#wrapper',
'<div class="%class%" style="text-align: center;">%text%</div>',
'graph'

View File

@ -80,9 +80,12 @@ graph.render(data);
<script type="text/javascript"{if(nonce, ' nonce="{nonce}"')}>
ajaxScrollInit(
'{url|urlescape}graph/{rev}?revcount=%next%&style={style}',
{revcount}+60,
function (htmlText, previousVal) \{ return previousVal + 60; },
'{url|urlescape}graph/%next%{graphvars%urlparameter}',
'{nextentry%"{node}"}', <!-- NEXTHASH
function (htmlText, previousVal) \{
var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
return m ? m[1] : null;
},
'#wrapper',
'<div class="%class%" style="text-align: center;">%text%</div>',
'graph'

View File

@ -41,7 +41,6 @@ Graph.prototype = {
this.cell = [2, 0];
this.columns = 0;
document.getElementById('nodebgs').innerHTML = '';
document.getElementById('graphnodes').innerHTML = '';
},
scale: function(height) {

View File

@ -1838,9 +1838,12 @@ Overviews
<script type="text/javascript">
ajaxScrollInit(
'/graph/3?revcount=%next%&style=gitweb',
60+60,
function (htmlText, previousVal) { return previousVal + 60; },
'/graph/%next%?graphtop=cad8025a2e87f88c06259790adfa15acb4080123&style=gitweb',
'', <!-- NEXTHASH
function (htmlText, previousVal) {
var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
return m ? m[1] : null;
},
'#wrapper',
'<div class="%class%" style="text-align: center;">%text%</div>',
'graph'

View File

@ -324,9 +324,12 @@ Some tests for hgweb in an empty repository
<script type="text/javascript">
ajaxScrollInit(
'/graph/-1?revcount=%next%&style=paper',
60+60,
function (htmlText, previousVal) { return previousVal + 60; },
'/graph/%next%?graphtop=0000000000000000000000000000000000000000',
'', <!-- NEXTHASH
function (htmlText, previousVal) {
var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
return m ? m[1] : null;
},
'#wrapper',
'<div class="%class%" style="text-align: center;">%text%</div>',
'graph'