pfaffman
(Jay Pfaffman)
26. Oktober 2021 um 14:35
1
EDIT: I’m reclassifying this as a bug, so that someone who understands this better than I can take a look at it.
a bunch of uploads had “unknown” as the extension. This means that it’s impossible to generate thumbnails. I think this happened when moving a backup to a new site and then needed to regenerate the thumbnails.
I think what should happen when you try to generate thumbnails and the extension is ‘unknown’ is to replace the extension, something like
upload.extension = upload.original_filename.split('.').last
It seems like if this were done somewhere that I’d not have spent 4 hours on this.
Wait. This looks like the problem. Why return false rather than get the extension from the filename?
opts = opts.merge(raise_on_error: false)
if fix_image_extension
OptimizedImage.create_for(self, width, height, opts)
else
nil
end
end
end
def fix_image_extension
return false if extension == "unknown"
begin
# this is relatively cheap once cached
original_path = Discourse.store.path_for(self)
if original_path.blank?
external_copy = Discourse.store.download(self) rescue nil
original_path = external_copy.try(:path)
end
image_info = FastImage.new(original_path) rescue nil
Gory details follow.
I moved a site from /community to community.example.com by doing a backup and restore. I fixed the uploads with a
RAILS_ENV=production bundle exec script/discourse remap '/community/uploads' '/uploads'
But the avatars are still the Gray Man.
When I look at user.user_avatar.custom_upload.url and paste that URL into the browser, I get the desired avatar. It seems like I need to “rebake” the users.
I thought that perhaps a
rake avatars:refresh
or
rake avatars:clean
might fix it, but no joy.
What am I missing?
1 „Gefällt mir“
IAmGav
(Gavin Perch)
26. Oktober 2021 um 14:41
2
In sidekiq there is a trigger to create missing avatars.
It takes a while, but that should help if I am not mistaken
2 „Gefällt mir“
pfaffman
(Jay Pfaffman)
26. Oktober 2021 um 14:49
3
Good one! That callls User.refresh_avatar, but sadly
user=User.find_by_username('broken_avatar_guy')
user.refresh_avatar
also isn’t solving this.
2 „Gefällt mir“
pfaffman
(Jay Pfaffman)
27. Oktober 2021 um 12:30
4
Here’s a clue:
ActionController::RoutingError (No route matches [GET] "/user_avatar/community.example.com/broken_user")
1 „Gefällt mir“
IAmGav
(Gavin Perch)
27. Oktober 2021 um 12:51
5
Do it update when the user logs into their account ?
pfaffman
(Jay Pfaffman)
27. Oktober 2021 um 12:54
6
I don’t believe so.
user.user_avatar.custom_upload has the correct URL, but https://community.example.com/user_avatar/community.example.com/bad_user/25/321_2.png has the missing avatgar image. I need to find the way to rebuild those avatar thumbnails.
IAmGav
(Gavin Perch)
27. Oktober 2021 um 12:56
7
there is a force_avatar_update in the user login that i saw in the code.
IAmGav
(Gavin Perch)
27. Oktober 2021 um 13:01
8
this could be very helpful, it looks like a job
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Jobs::FixOutOfSyncUserUploadedAvatar do
it 'should fix out of sync user uploaded avatars' do
user_with_custom_upload = Fabricate(:user)
custom_upload1 = Fabricate(:upload, user: user_with_custom_upload)
gravatar_upload1 = Fabricate(:upload, user: user_with_custom_upload)
user_with_custom_upload.update!(uploaded_avatar: custom_upload1)
user_with_custom_upload.user_avatar.update!(
custom_upload: custom_upload1,
gravatar_upload: gravatar_upload1
)
user_out_of_sync = Fabricate(:user)
custom_upload2 = Fabricate(:upload, user: user_out_of_sync)
gravatar_upload2 = Fabricate(:upload, user: user_out_of_sync)
prev_gravatar_upload = Fabricate(:upload, user: user_out_of_sync)
This file has been truncated. show original
pfaffman
(Jay Pfaffman)
27. Oktober 2021 um 18:25
9
Something must be wrong:
user=User.find_by_username('Tuomo')
upload_id=user.user_avatar.custom_upload.id
upload = Upload.find(upload_id)
Discourse.avatar_sizes.each do |size|
OptimizedImage.create_for(upload, size, size)
end
OptimizedImage.where(upload_id: upload_id)
ANd I get the no opimized images.
broken_uploads = Upload.where(extension: "unknown")
broken_uploads.each do |upload|
upload.extension = upload.original_filename.split('.').last
upload.save
end
fixes that.
Then I just need to generate new thumbnails, like this:
has_upload = UserAvatar.where("custom_upload_id > 0")
has_upload.each do |user_avatar|
Jobs.enqueue(:create_avatar_thumbnails,{upload_id: user_avatar.custom_upload_id})
end
2 „Gefällt mir“
pfaffman
(Jay Pfaffman)
10. November 2021 um 20:00
10
Ich glaube, das ist ein legitimer Fehler und Jeff hat ihn ed, aber er hat keine weitere Aufmerksamkeit bekommen.
Bin ich verrückt oder ist hier etwas kaputt?
2 „Gefällt mir“
Ich habe eine Website von /community nach community.example.com verschoben, indem ich ein Backup und eine Wiederherstellung durchgeführt habe
Ich schätze, wir sind diesem Problem bei keiner unserer Wiederherstellungen begegnet, denn worüber Sie sich hier beschweren, sind Wiederherstellungsartefakte, ja? Vielleicht spezifisch für dieses Backup und diese Wiederherstellung?
1 „Gefällt mir“