Commit cfedc31b authored by Phil Hughes's avatar Phil Hughes

Improve initial rendering of discussion notes

This improves the initial rendering performance of notes
by only creating a new TaskList for the whole app,
rather than on a per-note component basis.
parent ef58a640
...@@ -128,6 +128,7 @@ export default { ...@@ -128,6 +128,7 @@ export default {
eventHub.$once('fetchedNotesData', this.setDiscussions); eventHub.$once('fetchedNotesData', this.setDiscussions);
}, },
methods: { methods: {
...mapActions(['startTaskList']),
...mapActions('diffs', [ ...mapActions('diffs', [
'setBaseConfig', 'setBaseConfig',
'fetchDiffFiles', 'fetchDiffFiles',
...@@ -157,7 +158,13 @@ export default { ...@@ -157,7 +158,13 @@ export default {
if (this.isNotesFetched && !this.assignedDiscussions && !this.isLoading) { if (this.isNotesFetched && !this.assignedDiscussions && !this.isLoading) {
this.assignedDiscussions = true; this.assignedDiscussions = true;
requestIdleCallback(() => this.assignDiscussionsToDiff(), { timeout: 1000 }); requestIdleCallback(
() =>
this.assignDiscussionsToDiff()
.then(this.$nextTick)
.then(this.startTaskList),
{ timeout: 1000 },
);
} }
}, },
adjustView() { adjustView() {
......
...@@ -4,7 +4,6 @@ import noteEditedText from './note_edited_text.vue'; ...@@ -4,7 +4,6 @@ import noteEditedText from './note_edited_text.vue';
import noteAwardsList from './note_awards_list.vue'; import noteAwardsList from './note_awards_list.vue';
import noteAttachment from './note_attachment.vue'; import noteAttachment from './note_attachment.vue';
import noteForm from './note_form.vue'; import noteForm from './note_form.vue';
import TaskList from '../../task_list';
import autosave from '../mixins/autosave'; import autosave from '../mixins/autosave';
export default { export default {
...@@ -37,14 +36,12 @@ export default { ...@@ -37,14 +36,12 @@ export default {
}, },
mounted() { mounted() {
this.renderGFM(); this.renderGFM();
this.initTaskList();
if (this.isEditing) { if (this.isEditing) {
this.initAutoSave(this.note); this.initAutoSave(this.note);
} }
}, },
updated() { updated() {
this.initTaskList();
this.renderGFM(); this.renderGFM();
if (this.isEditing) { if (this.isEditing) {
...@@ -59,15 +56,6 @@ export default { ...@@ -59,15 +56,6 @@ export default {
renderGFM() { renderGFM() {
$(this.$refs['note-body']).renderGFM(); $(this.$refs['note-body']).renderGFM();
}, },
initTaskList() {
if (this.canEdit) {
this.taskList = new TaskList({
dataType: 'note',
fieldName: 'note',
selector: '.notes',
});
}
},
handleFormUpdate(note, parentElement, callback) { handleFormUpdate(note, parentElement, callback) {
this.$emit('handleFormUpdate', note, parentElement, callback); this.$emit('handleFormUpdate', note, parentElement, callback);
}, },
......
...@@ -46,6 +46,7 @@ export default { ...@@ -46,6 +46,7 @@ export default {
'is-requesting being-posted': this.isRequesting, 'is-requesting being-posted': this.isRequesting,
'disabled-content': this.isDeleting, 'disabled-content': this.isDeleting,
target: this.isTarget, target: this.isTarget,
'is-editable': this.note.current_user.can_edit,
}; };
}, },
canResolve() { canResolve() {
......
...@@ -122,6 +122,7 @@ export default { ...@@ -122,6 +122,7 @@ export default {
setTargetNoteHash: 'setTargetNoteHash', setTargetNoteHash: 'setTargetNoteHash',
toggleDiscussion: 'toggleDiscussion', toggleDiscussion: 'toggleDiscussion',
setNotesFetchedState: 'setNotesFetchedState', setNotesFetchedState: 'setNotesFetchedState',
startTaskList: 'startTaskList',
}), }),
getComponentName(discussion) { getComponentName(discussion) {
if (discussion.isSkeletonNote) { if (discussion.isSkeletonNote) {
...@@ -157,6 +158,7 @@ export default { ...@@ -157,6 +158,7 @@ export default {
this.isFetching = false; this.isFetching = false;
}) })
.then(() => this.$nextTick()) .then(() => this.$nextTick())
.then(() => this.startTaskList())
.then(() => this.checkLocationHash()) .then(() => this.checkLocationHash())
.catch(() => { .catch(() => {
this.setLoadingState(false); this.setLoadingState(false);
......
import Vue from 'vue';
import $ from 'jquery'; import $ from 'jquery';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import Visibility from 'visibilityjs'; import Visibility from 'visibilityjs';
import TaskList from '../../task_list';
import Flash from '../../flash'; import Flash from '../../flash';
import Poll from '../../lib/utils/poll'; import Poll from '../../lib/utils/poll';
import * as types from './mutation_types'; import * as types from './mutation_types';
...@@ -368,5 +370,13 @@ export const setCommentsDisabled = ({ commit }, data) => { ...@@ -368,5 +370,13 @@ export const setCommentsDisabled = ({ commit }, data) => {
commit(types.DISABLE_COMMENTS, data); commit(types.DISABLE_COMMENTS, data);
}; };
export const startTaskList = ({ dispatch }) =>
new TaskList({
dataType: 'note',
fieldName: 'note',
selector: '.notes .is-editable',
onSuccess: () => Vue.$nextTick(() => dispatch('startTaskList')),
});
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
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