Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset status cache when status_stat or media_attachment updates #9119

Merged
merged 2 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/media_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def focus
"#{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
Expand Down Expand Up @@ -230,4 +231,9 @@ def video_metadata(file)
bitrate: movie.bitrate,
}
end

def reset_parent_cache
return if status_id.nil?
Rails.cache.delete("statuses/#{status_id}")
end
end
4 changes: 0 additions & 4 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ def decrement_count!(key)
before_validation :set_local

class << self
def cache_ids
left_outer_joins(:status_stat).select('statuses.id, greatest(statuses.updated_at, status_stats.updated_at) AS updated_at')
end

def selectable_visibilities
visibilities.keys - %w(direct limited)
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/status_stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@

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