From 2e3f78d64ca68e21c68708d33291b9ac973073d3 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 20 Apr 2016 16:48:30 +0200 Subject: [PATCH] SONAR-7373 speed up scm rendering --- .../source-viewer/templates/source-viewer.hbs | 6 ++-- .../js/helpers/handlebars/eachWithPrevious.js | 34 +++++++++++++++++++ .../js/helpers/handlebars/ifSCMChanged2.js | 6 +--- 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 server/sonar-web/src/main/js/helpers/handlebars/eachWithPrevious.js diff --git a/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs b/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs index 82df2448ac3..570a91ce167 100644 --- a/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs +++ b/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer.hbs @@ -12,12 +12,12 @@ {{/if}} - {{#each source}} + {{#eachWithPrevious source}} @@ -85,7 +85,7 @@ {{/notEmpty}} - {{/each}} + {{/eachWithPrevious}}
- {{#ifSCMChanged2 ../source line}} + {{#ifSCMChanged2 this _previous}}
{{/ifSCMChanged2}}
{{#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 index 00000000000..70ddf847fb6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/handlebars/eachWithPrevious.js @@ -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; +}; diff --git a/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js b/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js index f2129bad5d7..c93bf045494 100644 --- a/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js +++ b/server/sonar-web/src/main/js/helpers/handlebars/ifSCMChanged2.js @@ -17,11 +17,7 @@ * 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); -- 2.39.5