Commit ab094e67eed54f5c29a33d2114cc91908e543972
Exists in
spb-stable
and in
2 other branches
Merge branch 'faster-diff-rendering' into 'master'
Faster diff rendering 1. Dont render link in separate template but use helper instead 2. Don't build new object but just reuse variables New note for diff is rendered per each diff line. Such simple improvements gives us 20..100% better performance depends on diff size
Showing
3 changed files
with
29 additions
and
6 deletions
Show diff stats
app/helpers/notes_helper.rb
@@ -42,4 +42,23 @@ module NotesHelper | @@ -42,4 +42,23 @@ module NotesHelper | ||
42 | project_id: noteable.project.id, | 42 | project_id: noteable.project.id, |
43 | }.to_json | 43 | }.to_json |
44 | end | 44 | end |
45 | + | ||
46 | + def link_to_new_diff_note(line_code) | ||
47 | + discussion_id = Note.build_discussion_id( | ||
48 | + @comments_target[:noteable_type], | ||
49 | + @comments_target[:noteable_id] || @comments_target[:commit_id], | ||
50 | + line_code | ||
51 | + ) | ||
52 | + | ||
53 | + data = { | ||
54 | + noteable_type: @comments_target[:noteable_type], | ||
55 | + noteable_id: @comments_target[:noteable_id], | ||
56 | + commit_id: @comments_target[:commit_id], | ||
57 | + line_code: line_code, | ||
58 | + discussion_id: discussion_id | ||
59 | + } | ||
60 | + | ||
61 | + link_to "", "javascript:;", class: "add-diff-note js-add-diff-note-button", | ||
62 | + data: data, title: "Add a comment to this line" | ||
63 | + end | ||
45 | end | 64 | end |
app/models/note.rb
@@ -122,11 +122,15 @@ class Note < ActiveRecord::Base | @@ -122,11 +122,15 @@ class Note < ActiveRecord::Base | ||
122 | 122 | ||
123 | discussions | 123 | discussions |
124 | end | 124 | end |
125 | - end | ||
126 | 125 | ||
127 | - # Determine whether or not a cross-reference note already exists. | ||
128 | - def self.cross_reference_exists?(noteable, mentioner) | ||
129 | - where(noteable_id: noteable.id, system: true, note: "_mentioned in #{mentioner.gfm_reference}_").any? | 126 | + def build_discussion_id(type, id, line_code) |
127 | + [:discussion, type.try(:underscore), id, line_code].join("-").to_sym | ||
128 | + end | ||
129 | + | ||
130 | + # Determine whether or not a cross-reference note already exists. | ||
131 | + def cross_reference_exists?(noteable, mentioner) | ||
132 | + where(noteable_id: noteable.id, system: true, note: "_mentioned in #{mentioner.gfm_reference}_").any? | ||
133 | + end | ||
130 | end | 134 | end |
131 | 135 | ||
132 | def commit_author | 136 | def commit_author |
@@ -194,7 +198,7 @@ class Note < ActiveRecord::Base | @@ -194,7 +198,7 @@ class Note < ActiveRecord::Base | ||
194 | end | 198 | end |
195 | 199 | ||
196 | def discussion_id | 200 | def discussion_id |
197 | - @discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id || commit_id, line_code].join("-").to_sym | 201 | + @discussion_id ||= Note.build_discussion_id(noteable_type, noteable_id || commit_id, line_code) |
198 | end | 202 | end |
199 | 203 | ||
200 | # Returns true if this is a downvote note, | 204 | # Returns true if this is a downvote note, |
app/views/projects/commits/_text_file.html.haml
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | %td.old_line | 13 | %td.old_line |
14 | = link_to raw(type == "new" ? " " : line_old), "##{line_code}", id: line_code | 14 | = link_to raw(type == "new" ? " " : line_old), "##{line_code}", id: line_code |
15 | - if @comments_allowed | 15 | - if @comments_allowed |
16 | - = render "projects/notes/diff_note_link", line_code: line_code | 16 | + = link_to_new_diff_note(line_code) |
17 | %td.new_line= link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code | 17 | %td.new_line= link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code |
18 | %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line) | 18 | %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line) |
19 | 19 |