diff options
author | Mike Lewis <mlewis@gitlab.com> | 2019-03-07 15:59:00 +0000 |
---|---|---|
committer | Mike Lewis <mlewis@gitlab.com> | 2019-03-07 15:59:00 +0000 |
commit | dbd7309a16bd3abc6c586b6c2df2beb317cfef95 (patch) | |
tree | 3fdd719c926ac80285f0dc93ef975625657d0fbb /lib/api/todos.rb | |
parent | 7be248334b350091e83d0335bf0c263071c6a67f (diff) | |
parent | b63efb09a5c864047924cd2d84527b47dd563d5f (diff) | |
download | gitlab-ce-reply-to-comment-documentation.tar.gz |
Merge branch 'master' into 'reply-to-comment-documentation'reply-to-comment-documentation
# Conflicts:
# doc/user/discussions/index.md
Diffstat (limited to 'lib/api/todos.rb')
-rw-r--r-- | lib/api/todos.rb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/api/todos.rb b/lib/api/todos.rb index 64ac8ece56c..d2196f05173 100644 --- a/lib/api/todos.rb +++ b/lib/api/todos.rb @@ -6,6 +6,8 @@ module API before { authenticate! } + helpers ::Gitlab::IssuableMetadata + ISSUABLE_TYPES = { 'merge_requests' => ->(iid) { find_merge_request_with_access(iid) }, 'issues' => ->(iid) { find_project_issue(iid) } @@ -42,6 +44,30 @@ module API def find_todos TodosFinder.new(current_user, params).execute end + + def issuable_and_awardable?(type) + obj_type = Object.const_get(type) + + (obj_type < Issuable) && (obj_type < Awardable) + rescue NameError + false + end + + def batch_load_issuable_metadata(todos, options) + # This should be paginated and will cause Rails to SELECT for all the Todos + todos_by_type = todos.group_by(&:target_type) + + todos_by_type.keys.each do |type| + next unless issuable_and_awardable?(type) + + collection = todos_by_type[type] + + next unless collection + + targets = collection.map(&:target) + options[type] = { issuable_metadata: issuable_meta_data(targets, type) } + end + end end desc 'Get a todo list' do @@ -51,7 +77,11 @@ module API use :pagination end get do - present paginate(find_todos), with: Entities::Todo, current_user: current_user + todos = paginate(find_todos.with_api_entity_associations) + options = { with: Entities::Todo, current_user: current_user } + batch_load_issuable_metadata(todos, options) + + present todos, options end desc 'Mark a todo as done' do |