DEV: Minor improvements to WordWatcher (#16735)

Follow-up to fd1dc91eed
This commit is contained in:
Alan Guo Xiang Tan 2022-05-24 10:23:54 +08:00 committed by GitHub
parent 1ee973e6e2
commit 6edf101d5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 11 deletions

View File

@ -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