Recalculate stats upon import deletion

This commit is contained in:
Eugene Burmakin 2025-02-15 18:49:30 +01:00
parent 2c39ebcaa9
commit 699e498670
4 changed files with 38 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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