]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7373 speed up scm rendering
authorStas Vilchik <vilchiks@gmail.com>
Wed, 20 Apr 2016 14:48:30 +0000 (16:48 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 20 Apr 2016 14:48:30 +0000 (16:48 +0200)
server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs
server/sonar-web/src/main/js/helpers/handlebars/eachWithPrevious.js [new file with mode: 0644]
server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js

index 82df2448ac32722fc8ba4a60947c54235f8abd0f..570a91ce1679fa31ca839953169becb73b46a860 100644 (file)
     {{/if}}
 
     <table class="source-table">
-      {{#each source}}
+      {{#eachWithPrevious source}}
         <tr class="source-line {{#eq line 0}}{{#empty issues}}hidden{{/empty}}{{/eq}}" {{#if line}}data-line-number="{{line}}"{{/if}}>
           <td class="source-meta source-line-number" {{#if line}}data-line-number="{{line}}"{{/if}}></td>
 
           <td class="source-meta source-line-scm" {{#if line}}data-line-number="{{line}}"{{/if}}>
-            {{#ifSCMChanged2 ../source line}}
+            {{#ifSCMChanged2 this _previous}}
               <div class="source-line-scm-inner" data-author="{{scmAuthor}}"></div>
             {{/ifSCMChanged2}}
           </td>
@@ -85,7 +85,7 @@
             {{/notEmpty}}
           </td>
         </tr>
-      {{/each}}
+      {{/eachWithPrevious}}
     </table>
 
     {{#if hasSourceAfter}}
diff --git a/server/sonar-web/src/main/js/helpers/handlebars/eachWithPrevious.js b/server/sonar-web/src/main/js/helpers/handlebars/eachWithPrevious.js
new file mode 100644 (file)
index 0000000..70ddf84
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import _ from 'underscore';
+
+module.exports = function (context, options) {
+  let ret = '';
+
+  if (Array.isArray(context)) {
+    context.forEach(function (element, index, list) {
+      const previous = index > 0 ? list[index - 1] : null;
+      const c = _.extend({ '_previous': previous }, element);
+      ret += options.fn(c);
+    });
+  }
+
+  return ret;
+};
index f2129bad5d73f6918d3abb10bd7777d77eaab9d3..c93bf045494bba14a0dcb0ac3ac83e67ffafa950 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import _ from 'underscore';
-
-module.exports = function (source, line, options) {
-  const currentLine = _.findWhere(source, { line });
-  const prevLine = _.findWhere(source, { line: line - 1 });
+module.exports = function (currentLine, prevLine, options) {
   let changed = true;
   if (currentLine && prevLine && currentLine.scmAuthor && prevLine.scmAuthor) {
     changed = (currentLine.scmAuthor !== prevLine.scmAuthor) || (currentLine.scmDate !== prevLine.scmDate);