about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb2
-rw-r--r--app/models/custom_emoji.rb10
-rw-r--r--app/models/status.rb2
3 files changed, 11 insertions, 3 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index ee47f04af..647b5c358 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -391,7 +391,7 @@ class Account < ApplicationRecord
   end
 
   def emojis
-    CustomEmoji.from_text(note, domain)
+    @emojis ||= CustomEmoji.from_text(note, domain)
   end
 
   before_create :generate_keys
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb
index 8235332f1..b99ed01f0 100644
--- a/app/models/custom_emoji.rb
+++ b/app/models/custom_emoji.rb
@@ -42,6 +42,8 @@ class CustomEmoji < ApplicationRecord
 
   include Attachmentable
 
+  after_commit :remove_entity_cache
+
   def local?
     domain.nil?
   end
@@ -58,11 +60,17 @@ class CustomEmoji < ApplicationRecord
 
       return [] if shortcodes.empty?
 
-      where(shortcode: shortcodes, domain: domain, disabled: false)
+      EntityCache.instance.emoji(shortcodes, domain)
     end
 
     def search(shortcode)
       where('"custom_emojis"."shortcode" ILIKE ?', "%#{shortcode}%")
     end
   end
+
+  private
+
+  def remove_entity_cache
+    Rails.cache.delete(EntityCache.instance.to_key(:emoji, shortcode, domain))
+  end
 end
diff --git a/app/models/status.rb b/app/models/status.rb
index 37f2db562..fbb1f89aa 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -160,7 +160,7 @@ class Status < ApplicationRecord
   end
 
   def emojis
-    CustomEmoji.from_text([spoiler_text, text].join(' '), account.domain)
+    @emojis ||= CustomEmoji.from_text([spoiler_text, text].join(' '), account.domain)
   end
 
   after_create_commit :store_uri, if: :local?