A platform for community discussion. Free, open, simple.
DEV: Do not cache chat onebox templates in development (#39956)
Martin Brennand4b1af8c8674
diff --git a/plugins/chat/lib/chat/engine.rb b/plugins/chat/lib/chat/engine.rbindex d541a4daac3..1d92de0f19a 100644--- a/plugins/chat/lib/chat/engine.rb+++ b/plugins/chat/lib/chat/engine.rb@@ -4,6 +4,15 @@ module ChatHAS_CHAT_ENABLED = "has_chat_enabled"LAST_CHAT_CHANNEL_ID = "last_chat_channel_id"+ ONEBOX_TEMPLATE_PATH = Rails.root.join("plugins/chat/lib/onebox/templates")+ MESSAGE_ONEBOX_TEMPLATE_PATH = ONEBOX_TEMPLATE_PATH.join("discourse_chat_message.mustache")+ CHANNEL_ONEBOX_TEMPLATE_PATH = ONEBOX_TEMPLATE_PATH.join("discourse_chat_channel.mustache")+ THREAD_ONEBOX_TEMPLATE_PATH = ONEBOX_TEMPLATE_PATH.join("discourse_chat_thread.mustache")+ private_constant :ONEBOX_TEMPLATE_PATH,+ :MESSAGE_ONEBOX_TEMPLATE_PATH,+ :CHANNEL_ONEBOX_TEMPLATE_PATH,+ :THREAD_ONEBOX_TEMPLATE_PATH+class Engine < ::Rails::Engineengine_name PLUGIN_NAMEisolate_namespace Chat@@ -19,26 +28,20 @@ module Chatenddef self.message_onebox_template- @message_onebox_template ||=- begin- path = "#{Rails.root}/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache"- File.read(path)- end+ return File.read(MESSAGE_ONEBOX_TEMPLATE_PATH) if Rails.env.development?++ @message_onebox_template ||= File.read(MESSAGE_ONEBOX_TEMPLATE_PATH)enddef self.channel_onebox_template- @channel_onebox_template ||=- begin- path = "#{Rails.root}/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache"- File.read(path)- end+ return File.read(CHANNEL_ONEBOX_TEMPLATE_PATH) if Rails.env.development?++ @channel_onebox_template ||= File.read(CHANNEL_ONEBOX_TEMPLATE_PATH)enddef self.thread_onebox_template- @thread_onebox_template ||=- begin- path = "#{Rails.root}/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache"- File.read(path)- end+ return File.read(THREAD_ONEBOX_TEMPLATE_PATH) if Rails.env.development?++ @thread_onebox_template ||= File.read(THREAD_ONEBOX_TEMPLATE_PATH)endend