mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
PERF: stop querying banner topic on every page hit
This commit is contained in:
parent
6ca87d281d
commit
c7bc692f40
@ -7,6 +7,7 @@ require_dependency 'rate_limiter'
|
||||
require_dependency 'crawler_detection'
|
||||
require_dependency 'json_error'
|
||||
require_dependency 'letter_avatar'
|
||||
require_dependency 'distributed_cache'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
include CurrentUser
|
||||
@ -271,11 +272,21 @@ class ApplicationController < ActionController::Base
|
||||
MultiJson.dump(data)
|
||||
end
|
||||
|
||||
def banner_json
|
||||
topic = Topic.where(archetype: Archetype.banner).limit(1).first
|
||||
banner = topic.present? ? topic.banner : {}
|
||||
def self.banner_json_cache
|
||||
@banner_json_cache ||= DistributedCache.new("banner_json")
|
||||
end
|
||||
|
||||
MultiJson.dump(banner)
|
||||
def banner_json
|
||||
|
||||
json = ApplicationController.banner_json_cache["json"]
|
||||
|
||||
unless json
|
||||
topic = Topic.where(archetype: Archetype.banner).limit(1).first
|
||||
banner = topic.present? ? topic.banner : {}
|
||||
ApplicationController.banner_json_cache["json"] = json = MultiJson.dump(banner)
|
||||
end
|
||||
|
||||
json
|
||||
end
|
||||
|
||||
def render_json_error(obj)
|
||||
|
@ -172,6 +172,12 @@ class Topic < ActiveRecord::Base
|
||||
unless skip_callbacks
|
||||
schedule_auto_close_job
|
||||
end
|
||||
|
||||
banner = "banner".freeze
|
||||
|
||||
if archetype_was == banner || archetype == banner
|
||||
ApplicationController.banner_json_cache.clear
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_default_values
|
||||
|
Loading…
Reference in New Issue
Block a user