Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.0 on 2022-01-18 at 14:00 UTC+1 (a few minutes of down time)

Commit c900c21e authored by micael.bergeron's avatar micael.bergeron
Browse files

add `#with_metadata` scope to remove a N+1 from the notes' API

parent 8acad6cd0631
......@@ -110,6 +110,7 @@ def values
includes(:author, :noteable, :updated_by,
project: [:project_members, { group: [:group_members] }])
scope :with_metadata, -> { includes(:system_note_metadata) }
after_initialize :ensure_discussion_id
before_validation :nullify_blank_type, :nullify_blank_line_code
......@@ -33,7 +33,7 @@ class Notes < Grape::API
# 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.
.reject { |n| n.cross_reference_not_visible_for?(current_user) }
present notes, with: Entities::Note
......@@ -50,7 +50,7 @@ class Notes < Grape::API
get ":id/#{noteables_str}/:noteable_id/notes/:note_id" do
noteable = find_project_noteable(noteables_str, params[:noteable_id])
note = noteable.notes.find(params[:note_id])
note = noteable.notes.with_metadata.find(params[:note_id])
can_read_note = can?(current_user, noteable_read_ability_name(noteable), noteable) && !note.cross_reference_not_visible_for?(current_user)
if can_read_note
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