Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c900c21e
Commit
c900c21e
authored
Nov 21, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add `#with_metadata` scope to remove a N+1 from the notes' API
parent
9ed91479
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
2 deletions
+3
-2
app/models/note.rb
app/models/note.rb
+1
-0
lib/api/notes.rb
lib/api/notes.rb
+2
-2
No files found.
app/models/note.rb
View file @
c900c21e
...
...
@@ -110,6 +110,7 @@ class Note < ActiveRecord::Base
includes
(
:author
,
:noteable
,
:updated_by
,
project:
[
:project_members
,
{
group:
[
:group_members
]
}])
end
scope
:with_metadata
,
->
{
includes
(
:system_note_metadata
)
}
after_initialize
:ensure_discussion_id
before_validation
:nullify_blank_type
,
:nullify_blank_line_code
...
...
lib/api/notes.rb
View file @
c900c21e
...
...
@@ -33,7 +33,7 @@ module 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.
paginate
(
noteable
.
notes
)
paginate
(
noteable
.
notes
.
with_metadata
)
.
reject
{
|
n
|
n
.
cross_reference_not_visible_for?
(
current_user
)
}
present
notes
,
with:
Entities
::
Note
else
...
...
@@ -50,7 +50,7 @@ module API
end
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment