From 6edf101d5f676d1a5209ff54116d40373d5127ba Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 24 May 2022 10:23:54 +0800 Subject: [PATCH] DEV: Minor improvements to WordWatcher (#16735) Follow-up to fd1dc91eedb8c50ddf595d831615d248c60039ba --- app/services/word_watcher.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/services/word_watcher.rb b/app/services/word_watcher.rb index 80ed9b45dbc..28f38b9a97e 100644 --- a/app/services/word_watcher.rb +++ b/app/services/word_watcher.rb @@ -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