From 5fc63a1d232608530a4cd4a45c34a2bed695169a Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Mon, 21 Jan 2019 22:25:54 +0100 Subject: Changed the Caching of User Avatars to be public and to 5 minutes --- app/controllers/concerns/uploads_actions.rb | 12 +++++++++++- app/controllers/uploads_controller.rb | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index c114e16edf8..7106c61e749 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -29,7 +29,13 @@ module UploadsActions def show 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' @@ -114,6 +120,10 @@ module UploadsActions nil end + def cache_privately? + true + end + def model strong_memoize(:model) { find_model } end diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index fa5d84633b5..20a5a0d2f42 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -70,6 +70,10 @@ class UploadsController < ApplicationController end end + def cache_privately? + true unless (User === model || Appearance === model) + end + def upload_model_class MODEL_CLASSES[params[:model]] || raise(UnknownUploadModelError) end -- cgit v1.2.1 From 86cda964cf7f289c8b0cd1efa80b3bd4bacfec4e Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Mon, 21 Jan 2019 23:58:54 +0100 Subject: Fixed static analysis error and 2 caching specs --- app/controllers/uploads_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 20a5a0d2f42..12f1d487f30 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -71,7 +71,7 @@ class UploadsController < ApplicationController end def cache_privately? - true unless (User === model || Appearance === model) + true unless User === model || Appearance === model end def upload_model_class -- cgit v1.2.1 From 2d057da183b35d4b4eca6eda8b005d7d068c342a Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Tue, 22 Jan 2019 11:09:04 +0100 Subject: Turned cache_privately? into cache_publicly? Also removed unnecessary comment --- app/controllers/concerns/uploads_actions.rb | 10 +++++----- app/controllers/uploads_controller.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index 7106c61e749..4ec0e94df9a 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -29,12 +29,12 @@ module UploadsActions def show return render_404 unless uploader&.exists? - if cache_privately? - expires_in 0.seconds, must_revalidate: true, private: true - else + if cache_publicly? # 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 + else + expires_in 0.seconds, must_revalidate: true, private: true end disposition = uploader.image_or_video? ? 'inline' : 'attachment' @@ -120,8 +120,8 @@ module UploadsActions nil end - def cache_privately? - true + def cache_publicly? + false end def model diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 12f1d487f30..519e7439205 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -70,8 +70,8 @@ class UploadsController < ApplicationController end end - def cache_privately? - true unless User === model || Appearance === model + def cache_publicly? + User === model || Appearance === model end def upload_model_class -- cgit v1.2.1