diff options
author | Ben Lubar <ben.lubar+github@gmail.com> | 2019-03-17 09:39:25 -0500 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2019-03-17 15:39:25 +0100 |
commit | c3d1594576227fcbc45d1da97f474acbd23d831b (patch) | |
tree | e3548d2ea61c67cfdd414cf72ea80382c31992b5 /app/controllers/application_controller.rb | |
parent | a20354a20b9dffada0e8d6170ebc2ff13c79baea (diff) |
Reduce server load caused by anonymous viewing. (#9059)
Do not start a session if the current user is not logged in for public-facing pages. Mark pages that don't care about sessions as publicly cacheable. Keep the max age as 0 so proxies and browsers will still try to retrieve an updated version but can still fall back to the stale version if the site is down or too slow. Fixes #9035.
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b54e7b008..990aff857 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -151,6 +151,11 @@ class ApplicationController < ActionController::Base response.headers['Vary'] = 'Accept' end + def mark_cacheable! + skip_session! + expires_in 0, public: true + end + def skip_session! request.session_options[:skip] = true end |