diff options
author | Jacob Schatz <jschatz1@gmail.com> | 2017-09-22 11:04:28 -0400 |
---|---|---|
committer | Jacob Schatz <jschatz1@gmail.com> | 2017-09-22 11:04:28 -0400 |
commit | 78439bbf3dc7eb2578a5adf18582d7fcf2ace90c (patch) | |
tree | 86768548049bd48e1d410e0ac358bce59ddc0ef8 | |
parent | 2f6f598746db4064c3f046b3bc56bc6ca737b13c (diff) | |
download | gitlab-ce-fast-issue-comments.tar.gz |
Initial partial loading.fast-issue-comments
-rw-r--r-- | app/assets/javascripts/notes/components/issue_notes_app.vue | 10 | ||||
-rw-r--r-- | app/assets/javascripts/notes/stores/actions.js | 11 | ||||
-rw-r--r-- | app/controllers/projects/issues_controller.rb | 31 |
3 files changed, 32 insertions, 20 deletions
diff --git a/app/assets/javascripts/notes/components/issue_notes_app.vue b/app/assets/javascripts/notes/components/issue_notes_app.vue index 1163b2f545e..74f0eb5bc19 100644 --- a/app/assets/javascripts/notes/components/issue_notes_app.vue +++ b/app/assets/javascripts/notes/components/issue_notes_app.vue @@ -76,6 +76,7 @@ getComponentData(note) { return note.individual_note ? note.notes[0] : note; }, + fetchNotes() { const options = { path: this.getNotesDataByProp('discussionsPath'), @@ -104,15 +105,6 @@ this.poll(); }, - checkLocationHash() { - const hash = gl.utils.getLocationHash(); - const element = document.getElementById(hash); - - if (hash && element) { - this.setTargetNoteHash(hash); - this.scrollToNoteIfNeeded($(element)); - } - }, }, created() { this.setNotesData(this.notesData); diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js index 34966ad63f0..f29db235615 100644 --- a/app/assets/javascripts/notes/stores/actions.js +++ b/app/assets/javascripts/notes/stores/actions.js @@ -18,8 +18,14 @@ export const setInitialNotes = ({ commit }, data) => commit(types.SET_INITIAL_NO export const setTargetNoteHash = ({ commit }, data) => commit(types.SET_TARGET_NOTE_HASH, data); export const toggleDiscussion = ({ commit }, data) => commit(types.TOGGLE_DISCUSSION, data); +const getNoteIdFromHash = () => { + const hash = gl.utils.getLocationHash(); + return hash ? parseInt(hash.split('_')[1]) : false; +} + export const fetchNotes = ({ commit, dispatch }, data) => { let { path, params } = data; + const noteID = getNoteIdFromHash() params = params || {}; function innerFetchNotes(path, params) { @@ -29,15 +35,20 @@ export const fetchNotes = ({ commit, dispatch }, data) => { .then((res) => { if (res.length > 0) { const newParams = params; + delete params.note_id; const lastNotes = res[res.length-1].notes; const lastNoteLength = lastNotes.length; newParams.after = lastNotes[lastNoteLength-1].id; commit(types.SET_INITIAL_NOTES, res); + return innerFetchNotes(path, newParams); } }); } + if(noteID) { + params = { note_id: noteID }; + } return innerFetchNotes(path, params); } diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 18728d0a1d0..c59de77b0e2 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -97,22 +97,31 @@ class Projects::IssuesController < Projects::ApplicationController def discussions limit = params.has_key?('limit') ? params[:limit] : 3 - notes = @issue.notes - .limit(limit) - .inc_relations_for_view - notes = notes.after_id(params[:after]) if params.has_key?('after') - notes = notes.before_id(params[:before]) if params.has_key?('before') + if params.has_key?('note_id') + note = @issue.notes.includes(:noteable).find(params[:note_id]) + notes = [note] + prepare_notes_for_rendering(notes) + discussions = Discussion.build_collection(notes, @issue) + render json: DiscussionSerializer.new(project: @project, noteable: @issue, current_user: current_user).represent(discussions) + else + notes = @issue.notes + .limit(limit) + .inc_relations_for_view - notes = notes.includes(:noteable) - .fresh - .reject { |n| n.cross_reference_not_visible_for?(current_user) } + notes = notes.after_id(params[:after]) if params.has_key?('after') + notes = notes.before_id(params[:before]) if params.has_key?('before') - prepare_notes_for_rendering(notes) + notes = notes.includes(:noteable) + .fresh + .reject { |n| n.cross_reference_not_visible_for?(current_user) } - discussions = Discussion.build_collection(notes, @issue) + prepare_notes_for_rendering(notes) - render json: DiscussionSerializer.new(project: @project, noteable: @issue, current_user: current_user).represent(discussions) + discussions = Discussion.build_collection(notes, @issue) + + render json: DiscussionSerializer.new(project: @project, noteable: @issue, current_user: current_user).represent(discussions) + end end def create |