about summary refs log tree commit diff
path: root/app/models/media_attachment.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-10-28 06:42:34 +0100
committerGitHub <noreply@github.com>2018-10-28 06:42:34 +0100
commit11b3ee4f4c1ede03f31dff4048283480ee22dd5f (patch)
tree7e69fcc5516c20a9a6258eae3b1f763414a9c024 /app/models/media_attachment.rb
parent93a1ab9030a358348addd55d5e18caaaec2d3a37 (diff)
Reset status cache when status_stat or media_attachment updates (#9119)
* Reset status cache when status_stat or media_attachment updates

Fix #8711

Media attachments are generally immutable, but admins can update
the sensitive flag, and this would ensure the change is visible
instantly. Same for updates to status stats. That is a regression
from #8185, because even the correct updated_at fetched from a join
doesn't seem to invalidate the cache.

* Remove join from Status#cache_ids since it has no effect
Diffstat (limited to 'app/models/media_attachment.rb')
-rw-r--r--app/models/media_attachment.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 1e4fae3de..1bfe02fd6 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -130,6 +130,7 @@ class MediaAttachment < ApplicationRecord
     "#{x},#{y}"
   end
 
+  after_commit :reset_parent_cache, on: :update
   before_create :prepare_description, unless: :local?
   before_create :set_shortcode
   before_post_process :set_type_and_extension
@@ -230,4 +231,9 @@ class MediaAttachment < ApplicationRecord
       bitrate: movie.bitrate,
     }
   end
+
+  def reset_parent_cache
+    return if status_id.nil?
+    Rails.cache.delete("statuses/#{status_id}")
+  end
 end