mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 20:51:50 +08:00
21 lines
582 B
Ruby
21 lines
582 B
Ruby
require "digest/sha1"
|
|
|
|
task "uploads:backfill_shas" => :environment do
|
|
RailsMultisite::ConnectionManagement.each_connection do |db|
|
|
puts "Backfilling #{db}"
|
|
Upload.select([:id, :sha, :url]).find_each do |u|
|
|
if u.sha.nil?
|
|
putc "."
|
|
path = "#{Rails.root}/public/#{u.url}"
|
|
sha = Digest::SHA1.file(path).hexdigest
|
|
begin
|
|
Upload.update_all ["sha = ?", sha], ["id = ?", u.id]
|
|
rescue ActiveRecord::RecordNotUnique
|
|
# not a big deal if we've got a few duplicates
|
|
end
|
|
end
|
|
end
|
|
end
|
|
puts "done"
|
|
end
|