diff options
Diffstat (limited to 'app/services/issuable/bulk_update_service.rb')
-rw-r--r-- | app/services/issuable/bulk_update_service.rb | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/app/services/issuable/bulk_update_service.rb b/app/services/issuable/bulk_update_service.rb index 8bcbb92cd0e..cd32cd78728 100644 --- a/app/services/issuable/bulk_update_service.rb +++ b/app/services/issuable/bulk_update_service.rb @@ -15,9 +15,13 @@ module Issuable def execute(type) ids = params.delete(:issuable_ids).split(",") set_update_params(type) - items = update_issuables(type, ids) + updated_issuables = update_issuables(type, ids) - response_success(payload: { count: items.size }) + if updated_issuables.present? && requires_count_cache_reset?(type) + schedule_group_issues_count_reset(updated_issuables) + end + + response_success(payload: { count: updated_issuables.size }) rescue ArgumentError => e response_error(e.message, 422) end @@ -53,7 +57,7 @@ module Issuable items.each do |issuable| next unless can?(current_user, :"update_#{type}", issuable) - update_class.new(issuable.issuing_parent, current_user, params).execute(issuable) + update_class.new(**update_class.constructor_container_arg(issuable.issuing_parent), current_user: current_user, params: params).execute(issuable) end items @@ -81,7 +85,18 @@ module Issuable def response_error(message, http_status) ServiceResponse.error(message: message, http_status: http_status) end + + def requires_count_cache_reset?(type) + type.to_sym == :issue && params.include?(:state_event) + end + + def schedule_group_issues_count_reset(updated_issuables) + group_ids = updated_issuables.map(&:project).map(&:namespace_id) + return if group_ids.empty? + + Issuables::ClearGroupsIssueCounterWorker.perform_async(group_ids) + end end end -Issuable::BulkUpdateService.prepend_if_ee('EE::Issuable::BulkUpdateService') +Issuable::BulkUpdateService.prepend_mod_with('Issuable::BulkUpdateService') |