Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce server load caused by anonymous viewing. #825

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/about_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ class AboutController < ApplicationController
before_action :set_instance_presenter, only: [:show, :more, :terms]

def show
skip_session! unless user_signed_in?

serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer)
@initial_state_json = serializable_resource.to_json
end

def more
skip_session! unless user_signed_in?

render layout: 'public'
end

def terms
skip_session! unless user_signed_in?

render layout: 'public'
end

Expand Down
6 changes: 6 additions & 0 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def show
respond_to do |format|
format.html do
use_pack 'public'
skip_session! unless user_signed_in?

@body_classes = 'with-modals'
@pinned_statuses = []
@endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
Expand All @@ -31,11 +33,15 @@ def show
end

format.atom do
skip_session!

@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? || entry.status.local_only? }))
end

format.rss do
skip_session!

@statuses = cache_collection(default_statuses.without_reblogs.without_replies.limit(PAGE_SIZE), Status)
render xml: RSS::AccountSerializer.render(@account, @statuses)
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@ def set_cache_headers

def skip_session!
request.session_options[:skip] = true
expires_in 0, public: true
end
end
1 change: 1 addition & 0 deletions app/controllers/follower_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def index
respond_to do |format|
format.html do
use_pack 'public'
skip_session! unless user_signed_in?

next if @account.user_hides_network?

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def initial_state_params
end

def default_redirect_path
skip_session!

if request.path.start_with?('/web')
new_user_session_path
elsif single_user_mode?
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def show
respond_to do |format|
format.html do
use_pack 'public'
skip_session! unless user_signed_in?

@body_classes = 'with-modals'

set_ancestors
Expand Down