Skip to content

Commit

Permalink
Cache featured collections, as well as outbox, followers and following (
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Gargron committed Apr 3, 2019
1 parent e315428 commit 50f56c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/controllers/activitypub/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/activitypub/outboxes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions app/controllers/follower_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class FollowerAccountsController < ApplicationController
include AccountControllerConcern

before_action :set_cache_headers

def index
respond_to do |format|
format.html do
Expand All @@ -17,6 +19,11 @@ def index
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,
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/following_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +19,11 @@ def index
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,
Expand Down

0 comments on commit 50f56c1

Please sign in to comment.