From da07adfe6c2137b07f3def1716b370329a9ec9cb Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 10 Sep 2024 09:21:40 -0400 Subject: [PATCH] Add `CustomEmoji.enabled` scope (#31830) --- app/lib/entity_cache.rb | 2 +- app/models/announcement_reaction.rb | 2 +- app/models/custom_emoji.rb | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/lib/entity_cache.rb b/app/lib/entity_cache.rb index 80b0046ee..e647dcab7 100644 --- a/app/lib/entity_cache.rb +++ b/app/lib/entity_cache.rb @@ -27,7 +27,7 @@ class EntityCache end unless uncached_ids.empty? - uncached = CustomEmoji.where(shortcode: shortcodes, domain: domain, disabled: false).index_by(&:shortcode) + 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) } end diff --git a/app/models/announcement_reaction.rb b/app/models/announcement_reaction.rb index 9881892c4..f953402b7 100644 --- a/app/models/announcement_reaction.rb +++ b/app/models/announcement_reaction.rb @@ -27,7 +27,7 @@ class AnnouncementReaction < ApplicationRecord private def set_custom_emoji - self.custom_emoji = CustomEmoji.local.find_by(disabled: false, shortcode: name) if name.present? + self.custom_emoji = CustomEmoji.local.enabled.find_by(shortcode: name) if name.present? end def queue_publish diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index 31ba91ad0..6e788c0c1 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -48,9 +48,10 @@ class CustomEmoji < ApplicationRecord scope :local, -> { where(domain: nil) } scope :remote, -> { where.not(domain: nil) } + scope :enabled, -> { where(disabled: false) } scope :alphabetic, -> { order(domain: :asc, shortcode: :asc) } scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches("%.#{domain}"))) } - scope :listed, -> { local.where(disabled: false).where(visible_in_picker: true) } + scope :listed, -> { local.enabled.where(visible_in_picker: true) } remotable_attachment :image, LIMIT