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 # We don't preload JSON on xhr or JSON request
return if request.xhr? || request.format.json? 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 preload_anonymous_data
if current_user if current_user

View file

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

View file

@ -1,6 +1,7 @@
class DraftController < ApplicationController class DraftController < ApplicationController
before_filter :ensure_logged_in 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 def show
seq = params[:sequence] || DraftSequence.current(current_user, params[:draft_key]) seq = params[:sequence] || DraftSequence.current(current_user, params[:draft_key])

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
class ForumsController < ApplicationController 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 :authorize_mini_profiler, only: [:status]
skip_before_filter :redirect_to_login_if_required, only: [:status] skip_before_filter :redirect_to_login_if_required, only: [:status]

View file

@ -1,5 +1,5 @@
class HighlightJsController < ApplicationController 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 def show
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do

View file

@ -1,6 +1,7 @@
class InvitesController < ApplicationController 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 skip_before_filter :redirect_to_login_if_required
before_filter :ensure_logged_in, only: [:destroy, :create, :resend_invite, :check_csv_chunk, :upload_csv_chunk] 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 # 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] 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 def markdown_id
markdown Post.find(params[:id].to_i) markdown Post.find(params[:id].to_i)

View file

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

View file

@ -4,7 +4,7 @@ require_dependency 'single_sign_on'
class SessionController < ApplicationController class SessionController < ApplicationController
skip_before_filter :redirect_to_login_if_required 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 def csrf
render json: {csrf: form_authenticity_token } render json: {csrf: form_authenticity_token }

View file

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

View file

@ -1,5 +1,5 @@
class SiteCustomizationsController < ApplicationController 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 def show
expires_in 1.year, public: true expires_in 1.year, public: true

View file

@ -1,6 +1,6 @@
class UploadsController < ApplicationController class UploadsController < ApplicationController
before_filter :ensure_logged_in, except: [:show] 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 def create
file = params[:file] || params[:files].first file = params[:file] || params[:files].first

View file

@ -3,7 +3,7 @@ require_dependency 'letter_avatar'
class UserAvatarsController < ApplicationController class UserAvatarsController < ApplicationController
DOT = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==") 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 def refresh_gravatar
user = User.find_by(username_lower: params[:username].downcase) user = User.find_by(username_lower: params[:username].downcase)