]> cat aescling's git repositories - mastodon.git/commitdiff
Cache featured collections, as well as outbox, followers and following (#10467)
authorThibG <thib@sitedethib.com>
Wed, 3 Apr 2019 23:30:44 +0000 (01:30 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 3 Apr 2019 23:30:44 +0000 (01:30 +0200)
app/controllers/activitypub/collections_controller.rb
app/controllers/activitypub/outboxes_controller.rb
app/controllers/follower_accounts_controller.rb
app/controllers/following_accounts_controller.rb

index 995da9c55dc0858f814d56f584c27e8a9274003c..853f4f9077c081d2e573e5de1961c338b65a5c2f 100644 (file)
@@ -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
index be4289b21c3f58531416b9914015bdc455d0ce59..438fa226e092b4784aed8f20290340fb414c7b56 100644 (file)
@@ -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
 
index aea42bd632ea8b346c294dbae577294e791d9556..713365ea568f8c51e58c6db9c391d339a785b465 100644 (file)
@@ -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,
index 03c4b10469b0ba6b3075085b67b6f199ba9fd88f..1bfd901cfb38b7c9ba85a425b4fd345d0f8bd9e9 100644 (file)
@@ -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,