diff options
author | Luke Duncalfe <lduncalfe@eml.cc> | 2019-07-04 15:33:14 +1200 |
---|---|---|
committer | Luke Duncalfe <lduncalfe@eml.cc> | 2019-07-10 12:13:48 +1200 |
commit | 073c8b25ea36b6b96eab05eb675e8726b1d5318e (patch) | |
tree | 5f83a17cf6e461106d8ddf8f1b84f743a09547d6 /app/models/discussion.rb | |
parent | 254f78f5dc36d4aef26d1ab2a924e4fa916221c6 (diff) | |
download | gitlab-ce-073c8b25ea36b6b96eab05eb675e8726b1d5318e.tar.gz |
GraphQL support for Notes created in discussions62826-graphql-note-mutations
A new `discussion_id` argument on the `createNote` mutation allows
people to create a note within that discussion.
The ability to lazy-load Discussions has been added, so
GraphQL.object_from_id can treat Discussions the same as AR objects and
batch load them.
https://gitlab.com/gitlab-org/gitlab-ce/issues/62826
https://gitlab.com/gitlab-org/gitlab-ee/issues/9489
Diffstat (limited to 'app/models/discussion.rb')
-rw-r--r-- | app/models/discussion.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb index ae13cdfd85f..dd896f77084 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -38,6 +38,17 @@ class Discussion grouped_notes.values.map { |notes| build(notes, context_noteable) } end + def self.lazy_find(discussion_id) + BatchLoader.for(discussion_id).batch do |discussion_ids, loader| + results = Note.where(discussion_id: discussion_ids).fresh.to_a.group_by(&:discussion_id) + results.each do |discussion_id, notes| + next if notes.empty? + + loader.call(discussion_id, Discussion.build(notes)) + end + end + end + # Returns an alphanumeric discussion ID based on `build_discussion_id` def self.discussion_id(note) Digest::SHA1.hexdigest(build_discussion_id(note).join("-")) |