Commit f93539af authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'discussion-perf-improvement' into 'master'

Improve initial rendering of discussion notes

See merge request gitlab-org/gitlab-ce!22607
parents 72f9c7eb a19c83dd
...@@ -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() {
......
...@@ -190,6 +190,7 @@ export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => { ...@@ -190,6 +190,7 @@ export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => {
.then(result => dispatch('updateDiscussion', result.discussion, { root: true })) .then(result => dispatch('updateDiscussion', result.discussion, { root: true }))
.then(discussion => dispatch('assignDiscussionsToDiff', [discussion])) .then(discussion => dispatch('assignDiscussionsToDiff', [discussion]))
.then(() => dispatch('closeDiffFileCommentForm', formData.diffFile.fileHash)) .then(() => dispatch('closeDiffFileCommentForm', formData.diffFile.fileHash))
.then(() => dispatch('startTaskList', null, { root: true }))
.catch(() => createFlash(s__('MergeRequests|Saving the comment failed'))); .catch(() => createFlash(s__('MergeRequests|Saving the comment failed')));
}; };
......
...@@ -6,7 +6,6 @@ import Autosize from 'autosize'; ...@@ -6,7 +6,6 @@ import Autosize from 'autosize';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import Flash from '../../flash'; import Flash from '../../flash';
import Autosave from '../../autosave'; import Autosave from '../../autosave';
import TaskList from '../../task_list';
import { import {
capitalizeFirstCharacter, capitalizeFirstCharacter,
convertToCamelCase, convertToCamelCase,
...@@ -146,7 +145,6 @@ export default { ...@@ -146,7 +145,6 @@ export default {
}); });
this.initAutoSave(); this.initAutoSave();
this.initTaskList();
}, },
methods: { methods: {
...mapActions([ ...mapActions([
...@@ -298,13 +296,6 @@ Please check your network connection and try again.`; ...@@ -298,13 +296,6 @@ Please check your network connection and try again.`;
]); ]);
} }
}, },
initTaskList() {
return new TaskList({
dataType: 'note',
fieldName: 'note',
selector: '.notes',
});
},
resizeTextarea() { resizeTextarea() {
this.$nextTick(() => { this.$nextTick(() => {
Autosize.update(this.$refs.textarea); Autosize.update(this.$refs.textarea);
......
...@@ -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';
...@@ -58,12 +60,13 @@ export const deleteNote = ({ commit, dispatch }, note) => ...@@ -58,12 +60,13 @@ export const deleteNote = ({ commit, dispatch }, note) =>
dispatch('updateMergeRequestWidget'); dispatch('updateMergeRequestWidget');
}); });
export const updateNote = ({ commit }, { endpoint, note }) => export const updateNote = ({ commit, dispatch }, { endpoint, note }) =>
service service
.updateNote(endpoint, note) .updateNote(endpoint, note)
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
commit(types.UPDATE_NOTE, res); commit(types.UPDATE_NOTE, res);
dispatch('startTaskList');
}); });
export const replyToDiscussion = ({ commit }, { endpoint, data }) => export const replyToDiscussion = ({ commit }, { endpoint, data }) =>
...@@ -85,6 +88,7 @@ export const createNewNote = ({ commit, dispatch }, { endpoint, data }) => ...@@ -85,6 +88,7 @@ export const createNewNote = ({ commit, dispatch }, { endpoint, data }) =>
commit(types.ADD_NEW_NOTE, res); commit(types.ADD_NEW_NOTE, res);
dispatch('updateMergeRequestWidget'); dispatch('updateMergeRequestWidget');
dispatch('startTaskList');
} }
return res; return res;
}); });
...@@ -260,6 +264,8 @@ const pollSuccessCallBack = (resp, commit, state, getters, dispatch) => { ...@@ -260,6 +264,8 @@ const pollSuccessCallBack = (resp, commit, state, getters, dispatch) => {
commit(types.ADD_NEW_NOTE, note); commit(types.ADD_NEW_NOTE, note);
} }
}); });
dispatch('startTaskList');
} }
commit(types.SET_LAST_FETCHED_AT, resp.last_fetched_at); commit(types.SET_LAST_FETCHED_AT, resp.last_fetched_at);
...@@ -368,5 +374,16 @@ export const setCommentsDisabled = ({ commit }, data) => { ...@@ -368,5 +374,16 @@ export const setCommentsDisabled = ({ commit }, data) => {
commit(types.DISABLE_COMMENTS, data); commit(types.DISABLE_COMMENTS, data);
}; };
export const startTaskList = ({ dispatch }) =>
Vue.nextTick(
() =>
new TaskList({
dataType: 'note',
fieldName: 'note',
selector: '.notes .is-editable',
onSuccess: () => 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 () => {};
---
title: Improve initial discussion rendering performance
merge_request: 22607
author:
type: changed
...@@ -396,6 +396,9 @@ describe('Actions Notes Store', () => { ...@@ -396,6 +396,9 @@ describe('Actions Notes Store', () => {
{ {
type: 'updateMergeRequestWidget', type: 'updateMergeRequestWidget',
}, },
{
type: 'startTaskList',
},
], ],
done, done,
); );
......
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