mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 12:57:29 +08:00
PERF: Reduce number of Redis hits per requests.
This commit is contained in:
parent
5aba30ede6
commit
4d840d10db
|
@ -36,6 +36,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
before_action :check_readonly_mode
|
||||
before_filter :handle_theme
|
||||
before_filter :set_current_user_for_logs
|
||||
before_filter :clear_notifications
|
||||
|
@ -61,7 +62,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def add_readonly_header
|
||||
response.headers['Discourse-Readonly'] = 'true' if Discourse.readonly_mode?
|
||||
response.headers['Discourse-Readonly'] = 'true' if @readonly_mode
|
||||
end
|
||||
|
||||
def perform_refresh_session
|
||||
|
@ -182,7 +183,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def clear_notifications
|
||||
if current_user && !Discourse.readonly_mode?
|
||||
if current_user && !@readonly_mode
|
||||
|
||||
cookie_notifications = cookies['cn'.freeze]
|
||||
notifications = request.headers['Discourse-Clear-Notifications'.freeze]
|
||||
|
@ -400,6 +401,10 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
private
|
||||
|
||||
def check_readonly_mode
|
||||
@readonly_mode = Discourse.readonly_mode?
|
||||
end
|
||||
|
||||
def locale_from_header
|
||||
begin
|
||||
# Rails I18n uses underscores between the locale and the region; the request
|
||||
|
@ -574,7 +579,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def block_if_readonly_mode
|
||||
return if request.fullpath.start_with?(path "/admin/backups")
|
||||
raise Discourse::ReadOnly.new if !(request.get? || request.head?) && Discourse.readonly_mode?
|
||||
raise Discourse::ReadOnly.new if !(request.get? || request.head?) && @readonly_mode
|
||||
end
|
||||
|
||||
def build_not_found_page(status = 404, layout = false)
|
||||
|
|
|
@ -276,7 +276,7 @@ module Discourse
|
|||
end
|
||||
|
||||
def self.readonly_mode?
|
||||
recently_readonly? || READONLY_KEYS.any? { |key| !!$redis.get(key) }
|
||||
recently_readonly? || $redis.mget(*READONLY_KEYS).compact.present?
|
||||
end
|
||||
|
||||
def self.last_read_only
|
||||
|
|
Loading…
Reference in New Issue
Block a user