mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
PERF: Cache ToS and Privacy Policy paths (#21860)
Checking if the topic exists happened often and that can cause performance issues.
This commit is contained in:
@ -597,6 +597,46 @@ module Discourse
|
||||
alias_method :base_url_no_path, :base_url_no_prefix
|
||||
end
|
||||
|
||||
def self.urls_cache
|
||||
@urls_cache ||= DistributedCache.new("urls_cache")
|
||||
end
|
||||
|
||||
def self.tos_url
|
||||
if SiteSetting.tos_url.present?
|
||||
SiteSetting.tos_url
|
||||
else
|
||||
urls_cache["tos"] ||= (
|
||||
if SiteSetting.tos_topic_id > 0 && Topic.exists?(id: SiteSetting.tos_topic_id)
|
||||
"#{Discourse.base_path}/tos"
|
||||
else
|
||||
:nil
|
||||
end
|
||||
)
|
||||
|
||||
urls_cache["tos"] != :nil ? urls_cache["tos"] : nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.privacy_policy_url
|
||||
if SiteSetting.privacy_policy_url.present?
|
||||
SiteSetting.privacy_policy_url
|
||||
else
|
||||
urls_cache["privacy_policy"] ||= (
|
||||
if SiteSetting.privacy_topic_id > 0 && Topic.exists?(id: SiteSetting.privacy_topic_id)
|
||||
"#{Discourse.base_path}/privacy"
|
||||
else
|
||||
:nil
|
||||
end
|
||||
)
|
||||
|
||||
urls_cache["privacy_policy"] != :nil ? urls_cache["privacy_policy"] : nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.clear_urls!
|
||||
urls_cache.clear
|
||||
end
|
||||
|
||||
LAST_POSTGRES_READONLY_KEY = "postgres:last_readonly"
|
||||
|
||||
READONLY_MODE_KEY_TTL ||= 60
|
||||
|
Reference in New Issue
Block a user