Commit 9eb5ebf9 authored by Micael Bergeron's avatar Micael Bergeron

Remove the injection of `Gitlab::IssuableMetadata` in the API

With the BatchLoader implementation in the
`Gitlab::Entities::IssuableEntity` it was not necessary anymore to
sent this object around.
parent daa21395
...@@ -42,7 +42,7 @@ module API ...@@ -42,7 +42,7 @@ module API
get ':id/(-/)epics' do get ':id/(-/)epics' do
epics = paginate(find_epics(finder_params: { group_id: user_group.id })).with_api_entity_associations epics = paginate(find_epics(finder_params: { group_id: user_group.id })).with_api_entity_associations
# issuable_metadata is the standard used by the Todo API # issuable_metadata has to be set because `Entities::Epic` doesn't inherit from `Entities::IssuableEntity`
extra_options = { issuable_metadata: Gitlab::IssuableMetadata.new(current_user, epics).data, with_labels_details: declared_params[:with_labels_details] } extra_options = { issuable_metadata: Gitlab::IssuableMetadata.new(current_user, epics).data, with_labels_details: declared_params[:with_labels_details] }
present epics, epic_options.merge(extra_options) present epics, epic_options.merge(extra_options)
end end
......
...@@ -14,19 +14,20 @@ module API ...@@ -14,19 +14,20 @@ module API
super super
end end
def issuable_metadata(user: nil) def issuable_metadata
# Because of the presence of the `user` parameter, we can't options.dig(:issuable_metadata, object.id) || lazy_issuable_metadata
# use the same lazy association.
return Gitlab::IssuableMetadata.new(user, [object]).data[object.id] if user
lazy_issuable_metadata
end end
protected protected
# This method will preload the `issuable_metadata` for the current
# entity according to the current top-level entity options, such
# as the current_user.
def lazy_issuable_metadata def lazy_issuable_metadata
BatchLoader.for(object).batch(key: :issuable_metadata) do |models, loader| BatchLoader.for(object).batch(key: [current_user, :issuable_metadata]) do |models, loader, args|
issuable_metadata = Gitlab::IssuableMetadata.new(nil, models) current_user = args[:key].first
issuable_metadata = Gitlab::IssuableMetadata.new(current_user, models)
metadata_by_id = issuable_metadata.data metadata_by_id = issuable_metadata.data
models.each do |issuable| models.each do |issuable|
...@@ -34,6 +35,12 @@ module API ...@@ -34,6 +35,12 @@ module API
end end
end end
end end
private
def current_user
options[:current_user]
end
end end
end end
end end
...@@ -22,7 +22,7 @@ module API ...@@ -22,7 +22,7 @@ module API
end end
expose(:user_notes_count) { |issue, options| issuable_metadata.user_notes_count } expose(:user_notes_count) { |issue, options| issuable_metadata.user_notes_count }
expose(:merge_requests_count) { |issue, options| issuable_metadata(user: options[:current_user]).merge_requests_count } expose(:merge_requests_count) { |issue, options| issuable_metadata.merge_requests_count }
expose(:upvotes) { |issue, options| issuable_metadata.upvotes } expose(:upvotes) { |issue, options| issuable_metadata.upvotes }
expose(:downvotes) { |issue, options| issuable_metadata.downvotes } expose(:downvotes) { |issue, options| issuable_metadata.downvotes }
expose :due_date expose :due_date
......
...@@ -26,14 +26,7 @@ module API ...@@ -26,14 +26,7 @@ module API
expose(:upvotes) { |merge_request, options| issuable_metadata.upvotes } expose(:upvotes) { |merge_request, options| issuable_metadata.upvotes }
expose(:downvotes) { |merge_request, options| issuable_metadata.downvotes } expose(:downvotes) { |merge_request, options| issuable_metadata.downvotes }
with_options using: Entities::UserBasic do expose :author, :assignees, :assignee, using: Entities::UserBasic
expose :author, as: :author
expose :assignees
expose :assignee do |merge_request, options|
merge_request.assignees.first
end
end
expose :source_project_id, :target_project_id expose :source_project_id, :target_project_id
expose :labels do |merge_request, options| expose :labels do |merge_request, options|
if options[:with_labels_details] if options[:with_labels_details]
......
...@@ -107,7 +107,6 @@ module API ...@@ -107,7 +107,6 @@ module API
with: Entities::Issue, with: Entities::Issue,
with_labels_details: declared_params[:with_labels_details], with_labels_details: declared_params[:with_labels_details],
current_user: current_user, current_user: current_user,
issuable_metadata: Gitlab::IssuableMetadata.new(current_user, issues).data,
include_subscribed: false include_subscribed: false
} }
...@@ -133,7 +132,6 @@ module API ...@@ -133,7 +132,6 @@ module API
with: Entities::Issue, with: Entities::Issue,
with_labels_details: declared_params[:with_labels_details], with_labels_details: declared_params[:with_labels_details],
current_user: current_user, current_user: current_user,
issuable_metadata: Gitlab::IssuableMetadata.new(current_user, issues).data,
include_subscribed: false, include_subscribed: false,
group: user_group group: user_group
} }
...@@ -170,7 +168,6 @@ module API ...@@ -170,7 +168,6 @@ module API
with_labels_details: declared_params[:with_labels_details], with_labels_details: declared_params[:with_labels_details],
current_user: current_user, current_user: current_user,
project: user_project, project: user_project,
issuable_metadata: Gitlab::IssuableMetadata.new(current_user, issues).data,
include_subscribed: false include_subscribed: false
} }
......
...@@ -93,7 +93,6 @@ module API ...@@ -93,7 +93,6 @@ module API
if params[:view] == 'simple' if params[:view] == 'simple'
options[:with] = Entities::MergeRequestSimple options[:with] = Entities::MergeRequestSimple
else else
options[:issuable_metadata] = Gitlab::IssuableMetadata.new(current_user, merge_requests).data
options[:skip_merge_status_recheck] = !declared_params[:with_merge_status_recheck] options[:skip_merge_status_recheck] = !declared_params[:with_merge_status_recheck]
end end
......
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