diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-23 20:21:19 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-23 20:21:19 +0300 |
commit | 99e8b77e5eaa8bd60c02935ee5baaebf31bc645a (patch) | |
tree | 2ca417c5d13237365f955e3036de296d5691a01e /lib/api | |
parent | 8f797950e8e5f92da800d67444a1f67bb6078f21 (diff) | |
parent | e24b9c2502613cc0df5b2a676236d1c36c02bca4 (diff) |
Merge branch 'sh-eliminate-gitaly-nplus-one-notes' into 'master'
Eliminate Gitaly N+1 queries with notes API
See merge request gitlab-org/gitlab-ce!32089
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/helpers/notes_helpers.rb | 2 | ||||
-rw-r--r-- | lib/api/notes.rb | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index 6bf9057fad7..b2bf6bf7417 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -3,6 +3,8 @@ module API module Helpers module NotesHelpers + include ::RendersNotes + def self.noteable_types # This is a method instead of a constant, allowing EE to more easily # extend it. diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 9381f045144..84563d66ee8 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -36,12 +36,13 @@ module API # page can have less elements than :per_page even if # there's more than one page. raw_notes = noteable.notes.with_metadata.reorder(order_options_with_tie_breaker) - notes = - # paginate() only works with a relation. This could lead to a - # mismatch between the pagination headers info and the actual notes - # array returned, but this is really a edge-case. - paginate(raw_notes) - .reject { |n| n.cross_reference_not_visible_for?(current_user) } + + # paginate() only works with a relation. This could lead to a + # mismatch between the pagination headers info and the actual notes + # array returned, but this is really a edge-case. + notes = paginate(raw_notes) + notes = prepare_notes_for_rendering(notes) + notes = notes.reject { |n| n.cross_reference_not_visible_for?(current_user) } present notes, with: Entities::Note end # rubocop: enable CodeReuse/ActiveRecord |