about summary refs log tree commit diff
path: root/app/models/custom_emoji.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-04-27 01:38:10 +0200
committerGitHub <noreply@github.com>2018-04-27 01:38:10 +0200
commita872392cd958167d5d9dd3fef613415cc9068774 (patch)
treeb062e9d8c7e87c29c74fb5416f3f60f39a172301 /app/models/custom_emoji.rb
parent63553c6b5c927950a45c5acb5af32af0dacee8c9 (diff)
Add entity cache (#7271)
* Add entity cache

Use a caching layer for mentions and custom emojis that are
dynamically extracted from text.

Reduce duplicate text extractions

* Fix code style issue
Diffstat (limited to 'app/models/custom_emoji.rb')
-rw-r--r--app/models/custom_emoji.rb10
1 files changed, 9 insertions, 1 deletions
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