From 389a817aad47fff8bcadc949a1804bd7f2d23053 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sun, 17 Nov 2019 14:57:46 -0600 Subject: Use `after_save` instead of `after_create`/`after_update` where methods should be called every time an object is changed. --- app/models/domain_block.rb | 2 +- app/models/status.rb | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index f7a87b443..4bb35ef8d 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -29,7 +29,7 @@ class DomainBlock < ApplicationRecord scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } scope :unprocessed, -> { where(processing: true) } - before_create :set_processing + before_save :set_processing def self.blocked?(domain) where(domain: domain, severity: :suspend).exists? diff --git a/app/models/status.rb b/app/models/status.rb index 4efa74b48..4e57c772e 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -336,9 +336,9 @@ class Status < ApplicationRecord after_create :set_poll_id after_create :process_bangtags, if: :local? - after_create :update_normalized_text - after_update :update_normalized_text + after_save :update_normalized_text + after_save :formatter_removed_cached class << self include SearchHelper @@ -627,7 +627,10 @@ class Status < ApplicationRecord return if destroyed? return unless (normalized_text.blank? && !text.blank?) || saved_change_to_text? self.normalized_text = normalize_status(self) - Rails.cache.delete("formatted_status:#{id}") + end + + def formatter_remove_cached + Rails.cache.delete("formatted_status:#{self.id}") end def set_conversation -- cgit