Avatars missing after import

I’ve got a vbulletin import for a hosted customer. The avatars have disappeared and are now showing as a generic blank person shape like this.

I’m pretty sure that they were there at some point. The URLs look like the should have something. Is there some way that I can find them?

Maybe related to that?

1 Like

Do you have a backup where you can check the URL?
Are they in the tombstone?

1 Like

I did a fresh import and all of the avatars are missing. Sidekiq still has 13M things to process, but I don’t see how that could be the problem. I did another import on another site with what I believe to be the same import script and the avatars are fine there.

pry(main)> User.find_by_username('MysteryManAvatar').uploaded_avatar
=> #<Upload:0x0000558a0d31b478
 id: 97,
 user_id: 114,
 original_filename: "clevername.jpg",
 filesize: 2028,
 width: 90,
 height: 67,
 url: "/uploads/default/original/1X/080817dcf59ddc838054fba9716b62fce9ae3d83.jpg",
 created_at: Thu, 19 Apr 2018 23:51:15 UTC +00:00,
 updated_at: Thu, 19 Apr 2018 23:51:15 UTC +00:00,
 sha1: "080817dcf59ddc838054fba9716b62fce9ae3d83",
 origin: nil,
 retain_hours: nil,
 extension: "jpg">

But that file isn’t in uploads (or tombstone).

I looked at Avatars not showing after import and that didn’t seem to be related.

I’ve done db restore from backup (there were some db migrations from old version and backup.sql.gz included only sql not uploads).

Unfortunately avatars are not showing on the site… (only default placeholder)

They seem to be correctly in the database and url correct and PNG file exists:

root@og-app:/var/www/discourse# rails c
[1] pry(main)> User.find_by_username('Overgrow').uploaded_avatar
=> #<Upload:0x0000565323a78880
 id: 2936,
 user_id: 1,
 original_filename: "avatar.png",
 filesize: 161585,
 width: nil,
 height: nil,
 url:     "/uploads/default/original/2X/f/fbba12aa89b1bc45676efcfa55affd4b7a76edf1.png",
 created_at: Sat, 03 Sep 2016 10:26:23 UTC +00:00,
 updated_at: Sat, 22 Feb 2020 11:57:35 UTC +00:00,
 sha1: "fbbe22aa89b1bc45676efcfa55affd4b7a76edf1",
 origin: nil,
 retain_hours: nil,
 extension: "unknown",
 thumbnail_width: nil,
 thumbnail_height: nil,
 etag: nil,
 secure: false,
 access_control_post_id: nil,
 original_sha1: nil>

Can you please advise what to try next? Thanks in advance!

Update:

Some avatars have regenerated in the background… Can I speed up the process? Or run it manually?

From my observations, could this part be sign of the problem?

extension: "unknown",

It seems like those regenerated have now this field filled:

extension: "JPG",

Somehow my database after backup restore and migration from 1.6 to 2.5 Discourse was missing width, height and extension values for Upload table (file pointers were correct and files on its place).

I have ended up creating a script that goes through all custom uploaded avatars and corrects extension, dimensions and re-generates all OptimizedImages with version 2 thumbnails which I was missing.

For anyone interested, here it is:

fix-avatars.rb

require File.expand_path("../../config/environment", __FILE__)

generated_count = 0

scope = UserAvatar.where("custom_upload_id > 0")

scope.find_each do |ua|

  upload_id = ua.custom_upload_id

  upload = Upload.find_by(id: upload_id)
  
  unless upload
    puts "\nno upload found for this user avatar"
    next
  end
  
  # fix unknown
  if upload.extension === 'unknown'
    upload.extension = nil 
    upload.save!
    puts "\rupload_id #{upload.id} extension unknown -> nil"
  end

  if upload.extension.nil?
    puts "\rupload_id #{upload.id} fixing extension"

    upload.fix_image_extension

    if upload.height == 0 || upload.width == 0
      puts "\rupload_id #{upload.id} fixing dimensions"
      upload.fix_dimensions!
    end

    # check optimized version
    correct_optimized = OptimizedImage.where(upload_id: upload_id)
      .where(version: 2)

    if correct_optimized.count < 1
      puts "\rupload_id #{upload.id} doesn't have version 2 thumbnails"

      # destroy old optimized
      puts "\rupload_id #{upload.id} deleting avatars"
      optimized = OptimizedImage.where(upload_id: upload_id)

      if optimized
        optimized.destroy_all
      end

      #generate optimized
      puts "\rupload_id #{upload.id} creating avatars"
      Discourse.avatar_sizes.each {|size| OptimizedImage.create_for(upload, size, size, allow_animation: SiteSetting.allow_animated_avatars)}

      generated_count += 1

      puts "\rGenerated #{generated_count} total avatars"

    end
  end

end
1 Like