about summary refs log tree commit diff
path: root/app/lib/formatter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/formatter.rb')
-rw-r--r--app/lib/formatter.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 6673f4b4b..5b8098ceb 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -32,6 +32,12 @@ class Formatter
   include ActionView::Helpers::TextHelper
 
   def format(status, **options)
+    Rails.cache.fetch(formatter_cache_key(status, options), expires_in: 1.hour) do
+      uncached_format(status, options)
+    end
+  end
+
+  def uncached_format(status, options)
     summary = nil
     raw_content = status.proper.text
     summary_mode = false
@@ -436,5 +442,17 @@ class Formatter
   def mention_html(account)
     "<span class=\"h-card\"><a href=\"#{encode(ActivityPub::TagManager.instance.url_for(account))}\" class=\"u-url mention\">@<span>#{encode(account.username)}</span></a></span>"
   end
+
+  def formatter_cache_key(status, options)
+    [
+      'format',
+      status.id.to_s,
+      options[:article_content]     ? '1' : '0',
+      options[:inline_poll_options] ? '1' : '0',
+      options[:plaintext]           ? '1' : '0',
+      options[:autoplay]            ? '1' : '0',
+      options[:custom_emojify]      ? '1' : '0',
+    ].join(':')
+  end
 end
 # rubocop:enable Metrics/ClassLength