diff options
Diffstat (limited to 'app/services/issuable')
-rw-r--r-- | app/services/issuable/bulk_update_service.rb | 23 | ||||
-rw-r--r-- | app/services/issuable/clone/attributes_rewriter.rb | 9 | ||||
-rw-r--r-- | app/services/issuable/clone/base_service.rb | 4 | ||||
-rw-r--r-- | app/services/issuable/common_system_notes_service.rb | 4 | ||||
-rw-r--r-- | app/services/issuable/destroy_label_links_service.rb | 35 | ||||
-rw-r--r-- | app/services/issuable/destroy_service.rb | 30 | ||||
-rw-r--r-- | app/services/issuable/import_csv/base_service.rb | 2 |
7 files changed, 82 insertions, 25 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') diff --git a/app/services/issuable/clone/attributes_rewriter.rb b/app/services/issuable/clone/attributes_rewriter.rb index 3861d88bce9..e1b4613726d 100644 --- a/app/services/issuable/clone/attributes_rewriter.rb +++ b/app/services/issuable/clone/attributes_rewriter.rb @@ -73,12 +73,17 @@ module Issuable copy_events(ResourceStateEvent.table_name, original_entity.resource_state_events) do |event| event.attributes - .except('id') + .except(*blocked_state_event_attributes) .merge(entity_key => new_entity.id, 'state' => ResourceStateEvent.states[event.state]) end end + # Overriden on EE::Issuable::Clone::AttributesRewriter + def blocked_state_event_attributes + ['id'] + end + def event_attributes_with_milestone(event, milestone) event.attributes .except('id') @@ -118,4 +123,4 @@ module Issuable end end -Issuable::Clone::AttributesRewriter.prepend_if_ee('EE::Issuable::Clone::AttributesRewriter') +Issuable::Clone::AttributesRewriter.prepend_mod_with('Issuable::Clone::AttributesRewriter') diff --git a/app/services/issuable/clone/base_service.rb b/app/services/issuable/clone/base_service.rb index 3c2bc527b12..f8a9eb3ece5 100644 --- a/app/services/issuable/clone/base_service.rb +++ b/app/services/issuable/clone/base_service.rb @@ -65,7 +65,7 @@ module Issuable end def close_issue - close_service = Issues::CloseService.new(old_project, current_user) + close_service = Issues::CloseService.new(project: old_project, current_user: current_user) close_service.execute(original_entity, notifications: false, system_note: false) end @@ -88,4 +88,4 @@ module Issuable end end -Issuable::Clone::BaseService.prepend_if_ee('EE::Issuable::Clone::BaseService') +Issuable::Clone::BaseService.prepend_mod_with('Issuable::Clone::BaseService') diff --git a/app/services/issuable/common_system_notes_service.rb b/app/services/issuable/common_system_notes_service.rb index fd2dc3787c2..aedd0c377c6 100644 --- a/app/services/issuable/common_system_notes_service.rb +++ b/app/services/issuable/common_system_notes_service.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Issuable - class CommonSystemNotesService < ::BaseService + class CommonSystemNotesService < ::BaseProjectService attr_reader :issuable def execute(issuable, old_labels: [], old_milestone: nil, is_update: true) @@ -109,4 +109,4 @@ module Issuable end end -Issuable::CommonSystemNotesService.prepend_if_ee('EE::Issuable::CommonSystemNotesService') +Issuable::CommonSystemNotesService.prepend_mod_with('Issuable::CommonSystemNotesService') diff --git a/app/services/issuable/destroy_label_links_service.rb b/app/services/issuable/destroy_label_links_service.rb new file mode 100644 index 00000000000..6fff9b5e8d2 --- /dev/null +++ b/app/services/issuable/destroy_label_links_service.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Issuable + class DestroyLabelLinksService + BATCH_SIZE = 100 + + def initialize(target_id, target_type) + @target_id = target_id + @target_type = target_type + end + + def execute + inner_query = + LabelLink + .select(:id) + .for_target(target_id, target_type) + .limit(BATCH_SIZE) + + delete_query = <<~SQL + DELETE FROM "#{LabelLink.table_name}" + WHERE id IN (#{inner_query.to_sql}) + SQL + + loop do + result = ActiveRecord::Base.connection.execute(delete_query) + + break if result.cmd_tuples == 0 + end + end + + private + + attr_reader :target_id, :target_type + end +end diff --git a/app/services/issuable/destroy_service.rb b/app/services/issuable/destroy_service.rb index d5aa84d8d6c..b75905fb5b0 100644 --- a/app/services/issuable/destroy_service.rb +++ b/app/services/issuable/destroy_service.rb @@ -3,15 +3,13 @@ module Issuable class DestroyService < IssuableBaseService def execute(issuable) - if issuable.destroy - after_destroy(issuable) - end + after_destroy(issuable) if issuable.destroy end private def after_destroy(issuable) - delete_todos(issuable) + delete_associated_records(issuable) issuable.update_project_counter_caches issuable.assignees.each(&:invalidate_cache_counts) end @@ -20,19 +18,23 @@ module Issuable issuable.resource_parent.group end - def delete_todos(issuable) + def delete_associated_records(issuable) actor = group_for(issuable) - if Feature.enabled?(:destroy_issuable_todos_async, actor, default_enabled: :yaml) - TodosDestroyer::DestroyedIssuableWorker - .perform_async(issuable.id, issuable.class.name) - else - TodosDestroyer::DestroyedIssuableWorker - .new - .perform(issuable.id, issuable.class.name) - end + delete_todos(actor, issuable) + delete_label_links(actor, issuable) + end + + def delete_todos(actor, issuable) + TodosDestroyer::DestroyedIssuableWorker + .perform_async(issuable.id, issuable.class.name) + end + + def delete_label_links(actor, issuable) + Issuable::LabelLinksDestroyWorker + .perform_async(issuable.id, issuable.class.name) end end end -Issuable::DestroyService.prepend_if_ee('EE::Issuable::DestroyService') +Issuable::DestroyService.prepend_mod_with('Issuable::DestroyService') diff --git a/app/services/issuable/import_csv/base_service.rb b/app/services/issuable/import_csv/base_service.rb index 5a2665285de..27dbc8b3cc4 100644 --- a/app/services/issuable/import_csv/base_service.rb +++ b/app/services/issuable/import_csv/base_service.rb @@ -68,7 +68,7 @@ module Issuable end def create_issuable(attributes) - create_issuable_class.new(@project, @user, attributes).execute + create_issuable_class.new(project: @project, current_user: @user, params: attributes).execute end def email_results_to_user |