mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 14:11:16 +08:00
Revert "PERF: use distributed cache for site text and category slugs"
This reverts commit a97f2eee054bbd5a252e7cc28ea11210b2a8a82d.
This commit is contained in:
@ -15,16 +15,39 @@ module SiteTextClassMethods
|
||||
@types << SiteTextType.new(text_type, format, opts)
|
||||
end
|
||||
|
||||
def text_for_cache
|
||||
@text_for_cache ||= DistributedCache.new("text_for_cache")
|
||||
end
|
||||
|
||||
def text_for(text_type, replacements=nil)
|
||||
text = nil
|
||||
text = text_for_cache[text_type] if replacements.blank?
|
||||
text = cached_text_for(text_type) if replacements.blank?
|
||||
text ||= uncached_text_for(text_type, replacements)
|
||||
end
|
||||
|
||||
def cached_text_for(text_type)
|
||||
ensure_subscribed!
|
||||
@mutex.synchronize do
|
||||
cache = @text_for_cache[RailsMultisite::ConnectionManagement.current_db]
|
||||
cache[text_type] if cache
|
||||
end
|
||||
end
|
||||
|
||||
def store_cached_text_for(text_type, result)
|
||||
ensure_subscribed!
|
||||
@mutex.synchronize do
|
||||
cache = (@text_for_cache[RailsMultisite::ConnectionManagement.current_db] ||= {})
|
||||
cache[text_type] = result
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_subscribed!
|
||||
return if @subscribed
|
||||
@mutex.synchronize do
|
||||
MessageBus.subscribe("/text_for") do |message|
|
||||
@mutex.synchronize do
|
||||
@text_for_cache[message.site_id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def uncached_text_for(text_type, replacements=nil)
|
||||
store_cache = replacements.blank?
|
||||
|
||||
@ -48,7 +71,7 @@ module SiteTextClassMethods
|
||||
|
||||
if store_cache
|
||||
result.freeze
|
||||
text_for_cache[text_type] = result
|
||||
store_cached_text_for(text_type, result)
|
||||
end
|
||||
|
||||
result
|
||||
|
Reference in New Issue
Block a user