DEV: look for avatars when analyzing missing uploads
This commit is contained in:
parent
990cd8c2e4
commit
97fe68e980
|
@ -998,17 +998,22 @@ end
|
||||||
def analyze_missing
|
def analyze_missing
|
||||||
puts "List of posts with missing images:"
|
puts "List of posts with missing images:"
|
||||||
sql = <<~SQL
|
sql = <<~SQL
|
||||||
SELECT post_id, url, sha1, extension
|
SELECT post_id, url, sha1, extension, uploads.id
|
||||||
FROM post_uploads pu
|
FROM post_uploads pu
|
||||||
JOIN uploads on uploads.id = pu.upload_id
|
RIGHT JOIN uploads on uploads.id = pu.upload_id
|
||||||
WHERE NOT verified
|
WHERE NOT verified
|
||||||
ORDER BY created_at
|
ORDER BY created_at
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
lookup = {}
|
lookup = {}
|
||||||
|
other = []
|
||||||
DB.query(sql).each do |r|
|
DB.query(sql).each do |r|
|
||||||
lookup[r.post_id] ||= []
|
if r.post_id
|
||||||
lookup[r.post_id] << [r.url, r.sha1, r.extension]
|
lookup[r.post_id] ||= []
|
||||||
|
lookup[r.post_id] << [r.url, r.sha1, r.extension]
|
||||||
|
else
|
||||||
|
other << r
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
posts = Post.where(id: lookup.keys)
|
posts = Post.where(id: lookup.keys)
|
||||||
|
@ -1023,6 +1028,17 @@ def analyze_missing
|
||||||
|
|
||||||
puts "Total missing uploads: #{Upload.where(verified: false).count}"
|
puts "Total missing uploads: #{Upload.where(verified: false).count}"
|
||||||
puts "Total problem posts: #{lookup.keys.count} with #{lookup.values.sum { |a| a.length } } missing uploads"
|
puts "Total problem posts: #{lookup.keys.count} with #{lookup.values.sum { |a| a.length } } missing uploads"
|
||||||
|
puts "Other missing uploads count: #{other.count}"
|
||||||
|
if other.count > 0
|
||||||
|
ids = other.map { |r| r.id }
|
||||||
|
count = DB.query_single(<<~SQL, ids: ids).first
|
||||||
|
SELECT COUNT(*) FROM users WHERE uploaded_avatar_id IN (:ids)
|
||||||
|
SQL
|
||||||
|
if count > 0
|
||||||
|
puts "Found #{count} uploaded avatars"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
task "uploads:analyze_missing" => :environment do
|
task "uploads:analyze_missing" => :environment do
|
||||||
|
|
Loading…
Reference in New Issue