DEV: Minor improvements to WordWatcher (#16735)
Follow-up to fd1dc91eed
This commit is contained in:
parent
1ee973e6e2
commit
6edf101d5f
|
@ -7,17 +7,14 @@ class WordWatcher
|
||||||
@raw = raw
|
@raw = raw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@cache_enabled = true
|
||||||
|
|
||||||
def self.disable_cache
|
def self.disable_cache
|
||||||
@disabled = true
|
@cache_enabled = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.enable_cache
|
def self.cache_enabled?
|
||||||
@disabled = false
|
@cache_enabled
|
||||||
end
|
|
||||||
|
|
||||||
# Don't cache in tests mode
|
|
||||||
def self.cache_disabled?
|
|
||||||
@disabled
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.words_for_action(action)
|
def self.words_for_action(action)
|
||||||
|
@ -37,12 +34,12 @@ class WordWatcher
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_cached_words(action)
|
def self.get_cached_words(action)
|
||||||
if cache_disabled?
|
if cache_enabled?
|
||||||
words_for_action(action).presence
|
|
||||||
else
|
|
||||||
Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do
|
Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do
|
||||||
words_for_action(action).presence
|
words_for_action(action).presence
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
words_for_action(action).presence
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue