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