From 7e390dcc253558b0a8ab3c465177e4c1c7d6bd3d Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Mon, 13 Aug 2018 11:55:30 +0200 Subject: Added constants for Render values + Optimised for Loop --- app/assets/javascripts/diffs/constants.js | 3 +++ app/assets/javascripts/diffs/store/mutations.js | 26 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/diffs/constants.js b/app/assets/javascripts/diffs/constants.js index 2fa8367f528..f68afa44837 100644 --- a/app/assets/javascripts/diffs/constants.js +++ b/app/assets/javascripts/diffs/constants.js @@ -25,3 +25,6 @@ export const CONTEXT_LINE_CLASS_NAME = 'diff-expanded'; export const UNFOLD_COUNT = 20; export const COUNT_OF_AVATARS_IN_GUTTER = 3; export const LENGTH_OF_AVATAR_TOOLTIP = 17; + +export const LINES_TO_BE_RENDERED_DIRECTLY = 100; +export const MAX_LINES_TO_BE_RENDERED = 2000; diff --git a/app/assets/javascripts/diffs/store/mutations.js b/app/assets/javascripts/diffs/store/mutations.js index e5c143696e8..50234483135 100644 --- a/app/assets/javascripts/diffs/store/mutations.js +++ b/app/assets/javascripts/diffs/store/mutations.js @@ -2,6 +2,7 @@ import Vue from 'vue'; import _ from 'underscore'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { findDiffFile, addLineReferences, removeMatchLine, addContextLines } from './utils'; +import { LINES_TO_BE_RENDERED_DIRECTLY, MAX_LINES_TO_BE_RENDERED } from '../constants'; import * as types from './mutation_types'; export default { @@ -17,31 +18,40 @@ export default { [types.SET_DIFF_DATA](state, data) { const diffData = convertObjectPropsToCamelCase(data, { deep: true }); let showingLines = 0; - diffData.diffFiles.forEach(file => { + const filesLength = diffData.diffFiles.length; + let i; + for (i = 0; i < filesLength; i += 1) { + const file = diffData.diffFiles[i]; if (file.parallelDiffLines) { - file.parallelDiffLines.forEach(line => { + const linesLength = file.parallelDiffLines.length; + let u = 0; + for (u = 0; u < linesLength; u += 1) { + const line = file.parallelDiffLines[u]; // eslint-disable-next-line no-param-reassign if (line.left) delete line.left.text; // eslint-disable-next-line no-param-reassign if (line.right) delete line.right.text; - }); + } } if (file.highlightedDiffLines) { - file.highlightedDiffLines.forEach(line => { + const linesLength = file.highlightedDiffLines.length; + let u = 0; + for (u = 0; u < linesLength; u += 1) { + const line = file.highlightedDiffLines[u]; // eslint-disable-next-line no-param-reassign delete line.text; - }); + } } if (file.highlightedDiffLines) { showingLines += file.parallelDiffLines.length; } Object.assign(file, { - renderIt: showingLines < 200, - collapsed: file.text && showingLines > 2000, + renderIt: showingLines < LINES_TO_BE_RENDERED_DIRECTLY, + collapsed: file.text && showingLines > MAX_LINES_TO_BE_RENDERED, }); - }); + } Object.assign(state, { ...diffData, -- cgit v1.2.1