Skip to content

Issuable destruction should be handled by a dedicated `Destroy` service

  • Centralize destruction logic into dedicated service(s)
  • Get rid of after_commit :update_project_counter_caches, on: :destroy (from Issue and MergeRequest) and move that into the service(s)

Care should be taken for the V4 API which uses a destroy_conditionally! helper:

    def destroy_conditionally!(resource, last_updated: nil)
      last_updated ||= resource.updated_at

      check_unmodified_since!(last_updated)

      status 204
      if block_given?
        yield resource
      else
        resource.destroy
      end
    end