Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsue445 <sue445@sue445.net>2017-08-08 14:31:55 +0300
committerRémy Coutable <remy@rymai.me>2017-08-08 14:31:55 +0300
commit7bc048616217b6cd1023c2972f882cf5d4a20309 (patch)
treed2a01dba74b23d3bb812b466bcf71ca77cd33bad /lib
parent6f555990aa7002f45ec713ed0811f0c845245459 (diff)
Expose noteable_iid in Note
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index bdea308ad5d..6ba4005dd0b 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -454,6 +454,9 @@ module API
end
class Note < Grape::Entity
+ # Only Issue and MergeRequest have iid
+ NOTEABLE_TYPES_WITH_IID = %w(Issue MergeRequest).freeze
+
expose :id
expose :note, as: :body
expose :attachment_identifier, as: :attachment
@@ -461,6 +464,9 @@ module API
expose :created_at, :updated_at
expose :system?, as: :system
expose :noteable_id, :noteable_type
+
+ # Avoid N+1 queries as much as possible
+ expose(:noteable_iid) { |note| note.noteable.iid if NOTEABLE_TYPES_WITH_IID.include?(note.noteable_type) }
end
class AwardEmoji < Grape::Entity