diff --git a/CHANGELOG.md b/CHANGELOG.md index ecfa1c72..34d90083 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed a bug where background jobs to import Immich and Photoprism geolocation data data could not be created by non-admin users. - Fixed a bug where upon point deletion there was an error it was not being removed from the map, while it was actually deleted from the database. #883 +- Fixed a bug where upon import deletion stats were not being recalculated. #824 ### Changed diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index ca3c34c8..3004cf8a 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -53,7 +53,7 @@ class ImportsController < ApplicationController end def destroy - @import.destroy! + Imports::Destroy.new(current_user, @import).call redirect_to imports_url, notice: 'Import was successfully destroyed.', status: :see_other end diff --git a/app/services/imports/destroy.rb b/app/services/imports/destroy.rb new file mode 100644 index 00000000..55efb008 --- /dev/null +++ b/app/services/imports/destroy.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class Imports::Destroy + attr_reader :user, :import + + def initialize(user, import) + @user = user + @import = import + end + + def call + @import.destroy! + + BulkStatsCalculatingJob.perform_later(@user.id) + end +end diff --git a/spec/services/imports/destroy_spec.rb b/spec/services/imports/destroy_spec.rb new file mode 100644 index 00000000..57f91790 --- /dev/null +++ b/spec/services/imports/destroy_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Imports::Destroy do + describe '#call' do + let!(:user) { create(:user) } + let!(:import) { create(:import, user: user) } + let(:service) { described_class.new(user, import) } + + it 'destroys the import' do + expect { service.call }.to change { Import.count }.by(-1) + end + + it 'enqueues a BulkStatsCalculatingJob' do + expect(BulkStatsCalculatingJob).to receive(:perform_later).with(user.id) + service.call + end + end +end