about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-11-17 14:57:46 -0600
committermultiple creatures <dev@multiple-creature.party>2019-11-17 14:57:46 -0600
commit389a817aad47fff8bcadc949a1804bd7f2d23053 (patch)
tree33f558b147a8122828a1bd2e6accbf8eccdfbe97
parent81942defe915389a130f17268b4e644bf8e2c7d5 (diff)
Use `after_save` instead of `after_create`/`after_update` where methods should be called every time an object is changed.
-rw-r--r--app/models/domain_block.rb2
-rw-r--r--app/models/status.rb9
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