mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
FIX: always serve new avatar for previous version
Previously we killed caching on old avatars cause we kept serving blank this meant we would front many more avatar requests after a version change This change ensures all old avatars do not cause a flood of requests on the server
This commit is contained in:
parent
ec27db78be
commit
f947e3c6cc
@ -99,7 +99,11 @@ class UserAvatarsController < ApplicationController
|
||||
upload_id, version = params[:version].split("_")
|
||||
|
||||
version = (version || OptimizedImage::VERSION).to_i
|
||||
return render_blank if version != OptimizedImage::VERSION
|
||||
|
||||
# old versions simply get new avatar
|
||||
if version > OptimizedImage::VERSION
|
||||
return render_blank
|
||||
end
|
||||
|
||||
upload_id = upload_id.to_i
|
||||
return render_blank unless upload_id > 0
|
||||
|
@ -102,6 +102,29 @@ describe UserAvatarsController do
|
||||
expect(response.headers["Last-Modified"]).to eq(optimized_image.upload.created_at.httpdate)
|
||||
end
|
||||
|
||||
it 'serves new version for old urls' do
|
||||
user = Fabricate(:user)
|
||||
SiteSetting.avatar_sizes = "45"
|
||||
|
||||
image = file_from_fixtures("cropped.png")
|
||||
upload = UploadCreator.new(image, "image.png").create_for(user.id)
|
||||
|
||||
user.update_columns(uploaded_avatar_id: upload.id)
|
||||
|
||||
get "/user_avatar/default/#{user.username}/45/#{upload.id}_1.png"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
image = response.body
|
||||
optimized = upload.get_optimized_image(45, 45, {})
|
||||
|
||||
expect(optimized.filesize).to eq(body.length)
|
||||
|
||||
# clean up images
|
||||
upload.destroy
|
||||
|
||||
end
|
||||
|
||||
it 'serves a correct last modified for render blank' do
|
||||
freeze_time
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user