1
0
mirror of https://github.com/mastodon/mastodon.git synced 2024-12-18 17:15:03 +01:00
mastodon/app/models/status_stat.rb
Eugen Rochko 11b3ee4f4c
Reset status cache when status_stat or media_attachment updates ()
* Reset status cache when status_stat or media_attachment updates

Fix 

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 , 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
2018-10-28 06:42:34 +01:00

26 lines
681 B
Ruby

# frozen_string_literal: true
# == Schema Information
#
# Table name: status_stats
#
# id :bigint(8) not null, primary key
# status_id :bigint(8) not null
# replies_count :bigint(8) default(0), not null
# reblogs_count :bigint(8) default(0), not null
# favourites_count :bigint(8) default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class StatusStat < ApplicationRecord
belongs_to :status, inverse_of: :status_stat
after_commit :reset_parent_cache
private
def reset_parent_cache
Rails.cache.delete("statuses/#{status_id}")
end
end