Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 47b2ba1

Browse files
committedMar 25, 2025·
Extract a method purge_one_batch
1 parent cb8798d commit 47b2ba1

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed
 

‎app/models/mixins/purging_mixin.rb

+14-11
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,7 @@ def purge_in_batches(conditions, window, total = 0, total_limit = nil)
228228
end
229229

230230
batch_records = unscoped.where(:id => batch_ids)
231-
count =
232-
if purge_method == :destroy
233-
destroyed = batch_records.destroy_all
234-
destroyed.detect { |d| !d.destroyed? }.tap do |failed|
235-
raise "failed removing record: #{failed.class.name} with id: #{failed.id} with error: #{failed.errors.full_messages}" if failed
236-
end
237-
238-
destroyed.count
239-
else
240-
batch_records.delete_all
241-
end
231+
count = purge_one_batch(batch_records)
242232
break if count == 0
243233

244234
total += count
@@ -248,5 +238,18 @@ def purge_in_batches(conditions, window, total = 0, total_limit = nil)
248238
end
249239
total
250240
end
241+
242+
def purge_one_batch(scope)
243+
if purge_method == :destroy
244+
destroyed = scope.destroy_all
245+
destroyed.detect { |d| !d.destroyed? }.tap do |failed|
246+
raise "failed removing record: #{failed.class.name} with id: #{failed.id} with error: #{failed.errors.full_messages}" if failed
247+
end
248+
249+
destroyed.count
250+
else
251+
scope.delete_all
252+
end
253+
end
251254
end
252255
end

0 commit comments

Comments
 (0)
Please sign in to comment.