about summary refs log tree commit diff
path: root/app/controllers/accounts_controller.rb
diff options
context:
space:
mode:
authorBen Lubar <ben.lubar+github@gmail.com>2019-03-17 09:39:25 -0500
committerEugen Rochko <eugen@zeonfederated.com>2019-03-17 15:39:25 +0100
commitc3d1594576227fcbc45d1da97f474acbd23d831b (patch)
treee3548d2ea61c67cfdd414cf72ea80382c31992b5 /app/controllers/accounts_controller.rb
parenta20354a20b9dffada0e8d6170ebc2ff13c79baea (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/accounts_controller.rb')
-rw-r--r--app/controllers/accounts_controller.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index a3410c1ef..abc68d2a4 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -10,6 +10,8 @@ class AccountsController < ApplicationController
   def show
     respond_to do |format|
       format.html do
+        mark_cacheable! unless user_signed_in?
+
         @body_classes      = 'with-modals'
         @pinned_statuses   = []
         @endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
@@ -30,17 +32,21 @@ class AccountsController < ApplicationController
       end
 
       format.atom do
+        mark_cacheable!
+
         @entries = @account.stream_entries.where(hidden: false).with_includes.paginate_by_max_id(PAGE_SIZE, params[:max_id], params[:since_id])
         render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, @entries.reject { |entry| entry.status.nil? }))
       end
 
       format.rss do
+        mark_cacheable!
+
         @statuses = cache_collection(default_statuses.without_reblogs.without_replies.limit(PAGE_SIZE), Status)
         render xml: RSS::AccountSerializer.render(@account, @statuses)
       end
 
       format.json do
-        skip_session!
+        mark_cacheable!
 
         render_cached_json(['activitypub', 'actor', @account], content_type: 'application/activity+json') do
           ActiveModelSerializers::SerializableResource.new(@account, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter)