From 07e6df0d40ce66a01be4241323580bf900c48317 Mon Sep 17 00:00:00 2001 From: Holger Huo Date: Thu, 10 Nov 2022 00:07:18 +0800 Subject: [PATCH] fix: custom emoji shortcode case not respected --- app/lib/entity_cache.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/lib/entity_cache.rb b/app/lib/entity_cache.rb index e647dcab7f..66fc30e2c1 100644 --- a/app/lib/entity_cache.rb +++ b/app/lib/entity_cache.rb @@ -19,22 +19,28 @@ class EntityCache shortcodes = Array(shortcodes) return [] if shortcodes.empty? - cached = Rails.cache.read_multi(*shortcodes.map { |shortcode| to_key(:emoji, shortcode, domain) }) + domain = domain.downcase if domain + + cached = Rails.cache.read_multi(*shortcodes.map { |shortcode| to_emoji(:emoji, shortcode, domain) }) uncached_ids = [] shortcodes.each do |shortcode| - uncached_ids << shortcode unless cached.key?(to_key(:emoji, shortcode, domain)) + uncached_ids << shortcode unless cached.key?(to_emoji(:emoji, shortcode, domain)) end unless uncached_ids.empty? uncached = CustomEmoji.enabled.where(shortcode: shortcodes, domain: domain).index_by(&:shortcode) - uncached.each_value { |item| Rails.cache.write(to_key(:emoji, item.shortcode, domain), item, expires_in: MAX_EXPIRATION) } + uncached.each_value { |item| Rails.cache.write(to_emoji(:emoji, item.shortcode, domain), item, expires_in: MAX_EXPIRATION) } end - shortcodes.filter_map { |shortcode| cached[to_key(:emoji, shortcode, domain)] || uncached[shortcode] } + shortcodes.filter_map { |shortcode| cached[to_emoji(:emoji, shortcode, domain)] || uncached[shortcode] } end def to_key(type, *ids) "#{type}:#{ids.compact.map(&:downcase).join(':')}" end + + def to_emoji(type, *ids) + "#{type}:#{ids.compact.join(':')}" + end end