From cc6e3c39001c11c82b198e357dd5d3e3fc032637 Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 4 Apr 2019 01:30:44 +0200 Subject: Cache featured collections, as well as outbox, followers and following (#10467) --- app/controllers/activitypub/collections_controller.rb | 16 +++++++++++----- app/controllers/activitypub/outboxes_controller.rb | 6 ++++++ app/controllers/follower_accounts_controller.rb | 7 +++++++ app/controllers/following_accounts_controller.rb | 9 +++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/controllers/activitypub/collections_controller.rb b/app/controllers/activitypub/collections_controller.rb index 995da9c55..853f4f907 100644 --- a/app/controllers/activitypub/collections_controller.rb +++ b/app/controllers/activitypub/collections_controller.rb @@ -6,13 +6,19 @@ class ActivityPub::CollectionsController < Api::BaseController before_action :set_account before_action :set_size before_action :set_statuses + before_action :set_cache_headers def show - render json: collection_presenter, - serializer: ActivityPub::CollectionSerializer, - adapter: ActivityPub::Adapter, - content_type: 'application/activity+json', - skip_activities: true + skip_session! + + render_cached_json(['activitypub', 'collection', @account, params[:id]], content_type: 'application/activity+json') do + ActiveModelSerializers::SerializableResource.new( + collection_presenter, + serializer: ActivityPub::CollectionSerializer, + adapter: ActivityPub::Adapter, + skip_activities: true + ) + end end private diff --git a/app/controllers/activitypub/outboxes_controller.rb b/app/controllers/activitypub/outboxes_controller.rb index be4289b21..438fa226e 100644 --- a/app/controllers/activitypub/outboxes_controller.rb +++ b/app/controllers/activitypub/outboxes_controller.rb @@ -7,8 +7,14 @@ class ActivityPub::OutboxesController < Api::BaseController before_action :set_account before_action :set_statuses + before_action :set_cache_headers def show + unless page_requested? + skip_session! + expires_in 1.minute, public: true + end + render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json' end diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb index aea42bd63..713365ea5 100644 --- a/app/controllers/follower_accounts_controller.rb +++ b/app/controllers/follower_accounts_controller.rb @@ -3,6 +3,8 @@ class FollowerAccountsController < ApplicationController include AccountControllerConcern + before_action :set_cache_headers + def index respond_to do |format| format.html do @@ -17,6 +19,11 @@ class FollowerAccountsController < ApplicationController format.json do raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network? + if params[:page].blank? + skip_session! + expires_in 3.minutes, public: true + end + render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb index 03c4b1046..1bfd901cf 100644 --- a/app/controllers/following_accounts_controller.rb +++ b/app/controllers/following_accounts_controller.rb @@ -3,9 +3,13 @@ class FollowingAccountsController < ApplicationController include AccountControllerConcern + before_action :set_cache_headers + def index respond_to do |format| format.html do + mark_cacheable! unless user_signed_in? + next if @account.user_hides_network? follows @@ -15,6 +19,11 @@ class FollowingAccountsController < ApplicationController format.json do raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network? + if params[:page].blank? + skip_session! + expires_in 3.minutes, public: true + end + render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, -- cgit