Fix cached posts including stale stats (#26409)
This commit is contained in:
		@@ -367,13 +367,25 @@ class Status < ApplicationRecord
 | 
			
		||||
 | 
			
		||||
      account_ids.uniq!
 | 
			
		||||
 | 
			
		||||
      status_ids = cached_items.map { |item| item.reblog? ? item.reblog_of_id : item.id }.uniq
 | 
			
		||||
 | 
			
		||||
      return if account_ids.empty?
 | 
			
		||||
 | 
			
		||||
      accounts = Account.where(id: account_ids).includes(:account_stat, :user).index_by(&:id)
 | 
			
		||||
 | 
			
		||||
      status_stats = StatusStat.where(status_id: status_ids).index_by(&:status_id)
 | 
			
		||||
 | 
			
		||||
      cached_items.each do |item|
 | 
			
		||||
        item.account = accounts[item.account_id]
 | 
			
		||||
        item.reblog.account = accounts[item.reblog.account_id] if item.reblog?
 | 
			
		||||
 | 
			
		||||
        if item.reblog?
 | 
			
		||||
          status_stat = status_stats[item.reblog.id]
 | 
			
		||||
          item.reblog.status_stat = status_stat if status_stat.present?
 | 
			
		||||
        else
 | 
			
		||||
          status_stat = status_stats[item.id]
 | 
			
		||||
          item.status_stat = status_stat if status_stat.present?
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user