mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-15 22:21:12 +00:00
Reduce complexity after recent refactor
This commit is contained in:
parent
6434d8ab4b
commit
b9638a6b82
|
@ -172,33 +172,18 @@ module Mastodon::CLI
|
||||||
|
|
||||||
objects.each do |object|
|
objects.each do |object|
|
||||||
path_segments = object.key.split('/')
|
path_segments = object.key.split('/')
|
||||||
path_segments.delete('cache')
|
|
||||||
|
|
||||||
unless VALID_PATH_SEGMENTS_SIZE.include?(path_segments.size)
|
|
||||||
progress.log(pastel.yellow("Unrecognized file found: #{object.key}"))
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
model_name = path_segments.first.classify
|
|
||||||
attachment_name = path_segments[1].singularize
|
|
||||||
record_id = path_segments[2...-2].join.to_i
|
|
||||||
file_name = path_segments.last
|
|
||||||
record = record_map.dig(model_name, record_id)
|
|
||||||
attachment = record&.public_send(attachment_name)
|
|
||||||
|
|
||||||
progress.increment
|
progress.increment
|
||||||
|
next unless orphaned_file?(path_segments)
|
||||||
next unless attachment.blank? || !attachment.variant?(file_name)
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
object.destroy unless dry_run?
|
object.destroy unless dry_run?
|
||||||
reclaimed_bytes += object.content_length
|
reclaimed_bytes += object.content_length
|
||||||
removed += 1
|
removed += 1
|
||||||
|
|
||||||
progress.log("Found and removed orphan: #{object.key}")
|
progress.log("Found and removed orphan: #{object.key}")
|
||||||
rescue => e
|
rescue => e
|
||||||
progress.log(pastel.red("Error processing #{object.key}: #{e}"))
|
progress.log(pastel.red("Error processing #{object.key}: #{e}"))
|
||||||
end
|
end
|
||||||
|
rescue UnrecognizedOrphanType
|
||||||
|
progress.log(pastel.yellow("Unrecognized file found: #{object.key}"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when :azure
|
when :azure
|
||||||
|
|
Loading…
Reference in New Issue
Block a user