PERF: avoid preloading json in cases where it is not needed

(uploads / avatars / non GET requests)
This commit is contained in:
Sam 2015-05-20 17:12:16 +10:00
parent 45bdd23689
commit e5888cf090
16 changed files with 22 additions and 16 deletions

View File

@ -168,6 +168,10 @@ class ApplicationController < ActionController::Base
# We don't preload JSON on xhr or JSON request
return if request.xhr? || request.format.json?
# if we are posting in makes no sense to preload
return if request.method != "GET"
# TODO should not be invoked on redirection so this should be further deferred
preload_anonymous_data
if current_user

View File

@ -1,6 +1,6 @@
class ClicksController < ApplicationController
skip_before_filter :check_xhr
skip_before_filter :check_xhr, :preload_json
def track
raise Discourse::NotFound unless params[:url]

View File

@ -1,6 +1,7 @@
class DraftController < ApplicationController
before_filter :ensure_logged_in
skip_before_filter :check_xhr
# TODO really do we need to skip this?
skip_before_filter :check_xhr, :preload_json
def show
seq = params[:sequence] || DraftSequence.current(current_user, params[:draft_key])

View File

@ -1,5 +1,5 @@
class EmailController < ApplicationController
skip_before_filter :check_xhr
skip_before_filter :check_xhr, :preload_json
layout 'no_ember'
before_filter :ensure_logged_in, only: :preferences_redirect

View File

@ -1,7 +1,5 @@
class EmbedController < ApplicationController
skip_before_filter :check_xhr
skip_before_filter :preload_json
skip_before_filter :verify_authenticity_token
skip_before_filter :check_xhr, :preload_json, :verify_authenticity_token
before_filter :ensure_embeddable

View File

@ -1,6 +1,6 @@
class ExportCsvController < ApplicationController
skip_before_filter :check_xhr, only: [:show]
skip_before_filter :preload_json, :check_xhr, only: [:show]
def export_entity
params.require(:entity)

View File

@ -1,6 +1,6 @@
class ForumsController < ApplicationController
skip_before_filter :check_xhr
skip_before_filter :preload_json, :check_xhr
skip_before_filter :authorize_mini_profiler, only: [:status]
skip_before_filter :redirect_to_login_if_required, only: [:status]

View File

@ -1,5 +1,5 @@
class HighlightJsController < ApplicationController
skip_before_filter :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show]
skip_before_filter :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show]
def show
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do

View File

@ -1,6 +1,7 @@
class InvitesController < ApplicationController
skip_before_filter :check_xhr
# TODO tighten this, why skip check on everything?
skip_before_filter :check_xhr, :preload_json
skip_before_filter :redirect_to_login_if_required
before_filter :ensure_logged_in, only: [:destroy, :create, :resend_invite, :check_csv_chunk, :upload_csv_chunk]

View File

@ -9,7 +9,7 @@ class PostsController < ApplicationController
# Need to be logged in for all actions here
before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link, :reply_history, :revisions, :latest_revision, :expand_embed, :markdown_id, :markdown_num, :cooked, :latest]
skip_before_filter :check_xhr, only: [:markdown_id, :markdown_num, :short_link]
skip_before_filter :preload_json, :check_xhr, only: [:markdown_id, :markdown_num, :short_link]
def markdown_id
markdown Post.find(params[:id].to_i)

View File

@ -1,6 +1,6 @@
class RobotsTxtController < ApplicationController
layout false
skip_before_filter :check_xhr
skip_before_filter :preload_json, :check_xhr
def index
path = if SiteSetting.allow_index_in_robots_txt

View File

@ -4,7 +4,7 @@ require_dependency 'single_sign_on'
class SessionController < ApplicationController
skip_before_filter :redirect_to_login_if_required
skip_before_filter :check_xhr, only: ['sso', 'sso_login', 'become', 'sso_provider']
skip_before_filter :preload_json, :check_xhr, only: ['sso', 'sso_login', 'become', 'sso_provider']
def csrf
render json: {csrf: form_authenticity_token }

View File

@ -2,6 +2,8 @@ require_dependency 'site_serializer'
class SiteController < ApplicationController
skip_before_filter :preload_json
def site
render json: Site.json_for(guardian)
end

View File

@ -1,5 +1,5 @@
class SiteCustomizationsController < ApplicationController
skip_before_filter :check_xhr, :redirect_to_login_if_required
skip_before_filter :preload_json, :check_xhr, :redirect_to_login_if_required
def show
expires_in 1.year, public: true

View File

@ -1,6 +1,6 @@
class UploadsController < ApplicationController
before_filter :ensure_logged_in, except: [:show]
skip_before_filter :check_xhr, only: [:show]
skip_before_filter :preload_json, :check_xhr, only: [:show]
def create
file = params[:file] || params[:files].first

View File

@ -3,7 +3,7 @@ require_dependency 'letter_avatar'
class UserAvatarsController < ApplicationController
DOT = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
skip_before_filter :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter]
skip_before_filter :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter]
def refresh_gravatar
user = User.find_by(username_lower: params[:username].downcase)