From e4f5114aaf9cea72df735443062c26803fee0ed6 Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Fri, 15 Sep 2023 19:52:28 +0200
Subject: [PATCH] Fix obsolete cache key in status cache invalidation logic
 (#26934)

---
 app/models/media_attachment.rb | 2 +-
 app/models/poll.rb             | 2 +-
 app/models/status_stat.rb      | 8 --------
 3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index bd0efb718..2d1b70661 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -407,6 +407,6 @@ class MediaAttachment < ApplicationRecord
   end
 
   def reset_parent_cache
-    Rails.cache.delete("statuses/#{status_id}") if status_id.present?
+    Rails.cache.delete("v3:statuses/#{status_id}") if status_id.present?
   end
 end
diff --git a/app/models/poll.rb b/app/models/poll.rb
index efa625eb5..72f04f00a 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -108,7 +108,7 @@ class Poll < ApplicationRecord
   def reset_parent_cache
     return if status_id.nil?
 
-    Rails.cache.delete("statuses/#{status_id}")
+    Rails.cache.delete("v3:statuses/#{status_id}")
   end
 
   def last_fetched_before_expiration?
diff --git a/app/models/status_stat.rb b/app/models/status_stat.rb
index d101cc178..47aa14477 100644
--- a/app/models/status_stat.rb
+++ b/app/models/status_stat.rb
@@ -16,8 +16,6 @@
 class StatusStat < ApplicationRecord
   belongs_to :status, inverse_of: :status_stat
 
-  after_commit :reset_parent_cache
-
   def replies_count
     [attributes['replies_count'], 0].max
   end
@@ -29,10 +27,4 @@ class StatusStat < ApplicationRecord
   def favourites_count
     [attributes['favourites_count'], 0].max
   end
-
-  private
-
-  def reset_parent_cache
-    Rails.cache.delete("statuses/#{status_id}")
-  end
 end