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
|
||||
end
|
||||
|
||||
@cache_enabled = true
|
||||
|
||||
def self.disable_cache
|
||||
@disabled = true
|
||||
@cache_enabled = false
|
||||
end
|
||||
|
||||
def self.enable_cache
|
||||
@disabled = false
|
||||
end
|
||||
|
||||
# Don't cache in tests mode
|
||||
def self.cache_disabled?
|
||||
@disabled
|
||||
def self.cache_enabled?
|
||||
@cache_enabled
|
||||
end
|
||||
|
||||
def self.words_for_action(action)
|
||||
|
@ -37,12 +34,12 @@ class WordWatcher
|
|||
end
|
||||
|
||||
def self.get_cached_words(action)
|
||||
if cache_disabled?
|
||||
words_for_action(action).presence
|
||||
else
|
||||
if cache_enabled?
|
||||
Discourse.cache.fetch(word_matcher_regexp_key(action), expires_in: 1.day) do
|
||||
words_for_action(action).presence
|
||||
end
|
||||
else
|
||||
words_for_action(action).presence
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue