Changed the Caching of User Avatars to be public and to 5 minutes
This commit is contained in:
parent
c141d0afb1
commit
5fc63a1d23
|
@ -29,7 +29,13 @@ module UploadsActions
|
||||||
def show
|
def show
|
||||||
return render_404 unless uploader&.exists?
|
return render_404 unless uploader&.exists?
|
||||||
|
|
||||||
expires_in 0.seconds, must_revalidate: true, private: true
|
if cache_privately?
|
||||||
|
expires_in 0.seconds, must_revalidate: true, private: true
|
||||||
|
else
|
||||||
|
# We need to reset caching from the applications controller to get rid of the no-store value
|
||||||
|
headers['Cache-Control'] = ''
|
||||||
|
expires_in 5.minutes, public: true, must_revalidate: false
|
||||||
|
end
|
||||||
|
|
||||||
disposition = uploader.image_or_video? ? 'inline' : 'attachment'
|
disposition = uploader.image_or_video? ? 'inline' : 'attachment'
|
||||||
|
|
||||||
|
@ -114,6 +120,10 @@ module UploadsActions
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cache_privately?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def model
|
def model
|
||||||
strong_memoize(:model) { find_model }
|
strong_memoize(:model) { find_model }
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,6 +70,10 @@ class UploadsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cache_privately?
|
||||||
|
true unless (User === model || Appearance === model)
|
||||||
|
end
|
||||||
|
|
||||||
def upload_model_class
|
def upload_model_class
|
||||||
MODEL_CLASSES[params[:model]] || raise(UnknownUploadModelError)
|
MODEL_CLASSES[params[:model]] || raise(UnknownUploadModelError)
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,13 @@ shared_examples 'content not cached without revalidation and no-store' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples 'content publicy cached' do
|
||||||
|
it 'ensures content is publicly cached' do
|
||||||
|
# Fixed in newer versions of ActivePack, it will only output a single `private`.
|
||||||
|
expect(subject['Cache-Control']).to eq('max-age=300, public')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe UploadsController do
|
describe UploadsController do
|
||||||
let!(:user) { create(:user, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
|
let!(:user) { create(:user, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
|
||||||
|
|
||||||
|
@ -184,7 +191,7 @@ describe UploadsController do
|
||||||
expect(response).to have_gitlab_http_status(200)
|
expect(response).to have_gitlab_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'content not cached without revalidation and no-store' do
|
it_behaves_like 'content publicy cached' do
|
||||||
subject do
|
subject do
|
||||||
get :show, params: { model: 'user', mounted_as: 'avatar', id: user.id, filename: 'dk.png' }
|
get :show, params: { model: 'user', mounted_as: 'avatar', id: user.id, filename: 'dk.png' }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue