Commit 78df5fe2 authored by Phil Hughes's avatar Phil Hughes

Merge branch '48789-remove-event-listeners-scroll' into 'master'

Resolve "Improve performance of MR Changes tab: reduce event listeners on scroll event"

Closes #48639 and #48789

See merge request gitlab-org/gitlab-ce!20558
parents eddf34f4 289530a0
...@@ -41,11 +41,6 @@ export default { ...@@ -41,11 +41,6 @@ export default {
required: true, required: true,
}, },
}, },
data() {
return {
activeFile: '',
};
},
computed: { computed: {
...mapState({ ...mapState({
isLoading: state => state.diffs.isLoading, isLoading: state => state.diffs.isLoading,
...@@ -126,14 +121,6 @@ export default { ...@@ -126,14 +121,6 @@ export default {
eventHub.$emit('fetchNotesData'); eventHub.$emit('fetchNotesData');
} }
}, },
setActive(filePath) {
this.activeFile = filePath;
},
unsetActive(filePath) {
if (this.activeFile === filePath) {
this.activeFile = '';
}
},
adjustView() { adjustView() {
if (this.shouldShow && this.isParallelView) { if (this.shouldShow && this.isParallelView) {
window.mrTabs.expandViewContainer(); window.mrTabs.expandViewContainer();
...@@ -195,7 +182,6 @@ export default { ...@@ -195,7 +182,6 @@ export default {
<changed-files <changed-files
:diff-files="diffFiles" :diff-files="diffFiles"
:active-file="activeFile"
/> />
<div <div
...@@ -207,8 +193,6 @@ export default { ...@@ -207,8 +193,6 @@ export default {
:key="file.newPath" :key="file.newPath"
:file="file" :file="file"
:current-user="currentUser" :current-user="currentUser"
@setActive="setActive(file.filePath)"
@unsetActive="unsetActive(file.filePath)"
/> />
</div> </div>
<no-changes v-else /> <no-changes v-else />
......
...@@ -16,13 +16,6 @@ export default { ...@@ -16,13 +16,6 @@ export default {
ClipboardButton, ClipboardButton,
}, },
mixins: [changedFilesMixin], mixins: [changedFilesMixin],
props: {
activeFile: {
type: String,
required: false,
default: '',
},
},
data() { data() {
return { return {
isStuck: false, isStuck: false,
...@@ -70,7 +63,7 @@ export default { ...@@ -70,7 +63,7 @@ export default {
pluralize, pluralize,
handleScroll() { handleScroll() {
if (!this.updating) { if (!this.updating) {
requestAnimationFrame(this.updateIsStuck); this.$nextTick(this.updateIsStuck);
this.updating = true; this.updating = true;
} }
}, },
...@@ -148,25 +141,8 @@ export default { ...@@ -148,25 +141,8 @@ export default {
/> />
<span <span
v-show="activeFile" class="js-diff-stats-additions-deletions-expanded
class="prepend-left-5" diff-stats-additions-deletions-expanded"
>
<strong class="prepend-right-5">
{{ truncatedDiffPath(activeFile) }}
</strong>
<clipboard-button
:text="activeFile"
:title="s__('Copy file name to clipboard')"
tooltip-placement="bottom"
tooltip-container="body"
class="btn btn-default btn-transparent btn-clipboard"
/>
</span>
<span
v-show="!isStuck"
id="diff-stats"
class="diff-stats-additions-deletions-expanded"
> >
with with
<strong class="cgreen"> <strong class="cgreen">
...@@ -177,6 +153,17 @@ export default { ...@@ -177,6 +153,17 @@ export default {
{{ pluralize(`${sumRemovedLines} deletion`, sumRemovedLines) }} {{ pluralize(`${sumRemovedLines} deletion`, sumRemovedLines) }}
</strong> </strong>
</span> </span>
<div
class="js-diff-stats-additions-deletions-collapsed
diff-stats-additions-deletions-collapsed float-right d-sm-none"
>
<strong class="cgreen">
+{{ sumAddedLines }}
</strong>
<strong class="cred">
-{{ sumRemovedLines }}
</strong>
</div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -40,7 +40,7 @@ export default { ...@@ -40,7 +40,7 @@ export default {
{{ n__('%d changed file', '%d changed files', diffFiles.length) }} {{ n__('%d changed file', '%d changed files', diffFiles.length) }}
</span> </span>
<icon <icon
:size="8" class="caret-icon"
name="chevron-down" name="chevron-down"
/> />
</button> </button>
......
...@@ -25,7 +25,6 @@ export default { ...@@ -25,7 +25,6 @@ export default {
}, },
data() { data() {
return { return {
isActive: false,
isLoadingCollapsedDiff: false, isLoadingCollapsedDiff: false,
forkMessageVisible: false, forkMessageVisible: false,
}; };
...@@ -48,12 +47,6 @@ export default { ...@@ -48,12 +47,6 @@ export default {
return this.isCollapsed && !this.isLoadingCollapsedDiff && !this.file.tooLarge; return this.isCollapsed && !this.isLoadingCollapsedDiff && !this.file.tooLarge;
}, },
}, },
mounted() {
document.addEventListener('scroll', this.handleScroll);
},
beforeDestroy() {
document.removeEventListener('scroll', this.handleScroll);
},
methods: { methods: {
...mapActions('diffs', ['loadCollapsedDiff']), ...mapActions('diffs', ['loadCollapsedDiff']),
handleToggle() { handleToggle() {
...@@ -65,36 +58,6 @@ export default { ...@@ -65,36 +58,6 @@ export default {
this.file.collapsed = !this.file.collapsed; this.file.collapsed = !this.file.collapsed;
} }
}, },
handleScroll() {
if (!this.updating) {
requestAnimationFrame(this.scrollUpdate.bind(this));
this.updating = true;
}
},
scrollUpdate() {
const header = document.querySelector('.js-diff-files-changed');
if (!header) {
this.updating = false;
return;
}
const { top, bottom } = this.$el.getBoundingClientRect();
const { top: topOfFixedHeader, bottom: bottomOfFixedHeader } = header.getBoundingClientRect();
const headerOverlapsContent = top < topOfFixedHeader && bottom > bottomOfFixedHeader;
const fullyAboveHeader = bottom < bottomOfFixedHeader;
const fullyBelowHeader = top > topOfFixedHeader;
if (headerOverlapsContent && !this.isActive) {
this.$emit('setActive');
this.isActive = true;
} else if (this.isActive && (fullyAboveHeader || fullyBelowHeader)) {
this.$emit('unsetActive');
this.isActive = false;
}
this.updating = false;
},
handleLoadCollapsedDiff() { handleLoadCollapsedDiff() {
this.isLoadingCollapsedDiff = true; this.isLoadingCollapsedDiff = true;
......
...@@ -518,6 +518,12 @@ ...@@ -518,6 +518,12 @@
outline: none; outline: none;
color: $gl-link-hover-color; color: $gl-link-hover-color;
} }
.caret-icon {
position: relative;
top: 2px;
left: -1px;
}
} }
// Mobile // Mobile
......
---
title: Improves performance on Merge Request diff tab by removing the scroll event
listeners being added to every file
merge_request:
author:
type: performance
...@@ -1666,9 +1666,6 @@ msgstr "" ...@@ -1666,9 +1666,6 @@ msgstr ""
msgid "Copy commit SHA to clipboard" msgid "Copy commit SHA to clipboard"
msgstr "" msgstr ""
msgid "Copy file name to clipboard"
msgstr ""
msgid "Copy file path to clipboard" msgid "Copy file path to clipboard"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment