changeset 35416:f84b01257e06

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.
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 11 Dec 2017 15:43:56 +0800
parents a48af4993aa0
children 83014fa95435
files mercurial/hgweb/webcommands.py mercurial/templates/gitweb/graph.tmpl mercurial/templates/monoblue/graph.tmpl mercurial/templates/paper/graph.tmpl mercurial/templates/static/mercurial.js tests/test-hgweb-commands.t tests/test-hgweb-empty.t
diffstat 7 files changed, 56 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Mon Dec 11 13:47:58 2017 +0800
+++ b/mercurial/hgweb/webcommands.py	Mon Dec 11 15:43:56 2017 +0800
@@ -1207,6 +1207,10 @@
     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 @@
     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 @@
         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 @@
     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)
--- a/mercurial/templates/gitweb/graph.tmpl	Mon Dec 11 13:47:58 2017 +0800
+++ b/mercurial/templates/gitweb/graph.tmpl	Mon Dec 11 15:43:56 2017 +0800
@@ -67,9 +67,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'
--- a/mercurial/templates/monoblue/graph.tmpl	Mon Dec 11 13:47:58 2017 +0800
+++ b/mercurial/templates/monoblue/graph.tmpl	Mon Dec 11 15:43:56 2017 +0800
@@ -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'
--- a/mercurial/templates/paper/graph.tmpl	Mon Dec 11 13:47:58 2017 +0800
+++ b/mercurial/templates/paper/graph.tmpl	Mon Dec 11 15:43:56 2017 +0800
@@ -80,9 +80,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'
--- a/mercurial/templates/static/mercurial.js	Mon Dec 11 13:47:58 2017 +0800
+++ b/mercurial/templates/static/mercurial.js	Mon Dec 11 15:43:56 2017 +0800
@@ -41,7 +41,6 @@
 		this.cell = [2, 0];
 		this.columns = 0;
 		document.getElementById('nodebgs').innerHTML = '';
-		document.getElementById('graphnodes').innerHTML = '';
 	},
 
 	scale: function(height) {
--- a/tests/test-hgweb-commands.t	Mon Dec 11 13:47:58 2017 +0800
+++ b/tests/test-hgweb-commands.t	Mon Dec 11 15:43:56 2017 +0800
@@ -1838,9 +1838,12 @@
   
   <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'
--- a/tests/test-hgweb-empty.t	Mon Dec 11 13:47:58 2017 +0800
+++ b/tests/test-hgweb-empty.t	Mon Dec 11 15:43:56 2017 +0800
@@ -324,9 +324,12 @@
   
   <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'