From 795f0107d23c1c9bd039f6449fa1e094ab7653a7 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 28 Oct 2018 06:35:03 +0100 Subject: Include preview cards in status entity in REST API (#9120) * Include preview cards in status entity in REST API * Display preview card in-stream * Improve in-stream display of preview cards --- app/models/status.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/models/status.rb') diff --git a/app/models/status.rb b/app/models/status.rb index bcb7dd373..cb2c01040 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -89,6 +89,7 @@ class Status < ApplicationRecord :conversation, :status_stat, :tags, + :preview_cards, :stream_entry, active_mentions: :account, reblog: [ @@ -96,6 +97,7 @@ class Status < ApplicationRecord :application, :stream_entry, :tags, + :preview_cards, :media_attachments, :conversation, :status_stat, @@ -163,6 +165,10 @@ class Status < ApplicationRecord reblog end + def preview_card + preview_cards.first + end + def title if destroyed? "#{account.acct} deleted status" -- cgit From 11b3ee4f4c1ede03f31dff4048283480ee22dd5f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 28 Oct 2018 06:42:34 +0100 Subject: 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 --- app/models/media_attachment.rb | 6 ++++++ app/models/status.rb | 4 ---- app/models/status_stat.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'app/models/status.rb') 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 diff --git a/app/models/status.rb b/app/models/status.rb index cb2c01040..32fedb924 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -240,10 +240,6 @@ class Status < ApplicationRecord 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 diff --git a/app/models/status_stat.rb b/app/models/status_stat.rb index 9d358776b..024c467e7 100644 --- a/app/models/status_stat.rb +++ b/app/models/status_stat.rb @@ -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 -- cgit