Get rid of the `Formatter` cache. It isn't worth the admin headaches.
parent
345c6beb7e
commit
59ef948640
|
@ -13,8 +13,6 @@ class Settings::ProfilesController < Settings::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
Rails.cache.delete("formatted_account:#{@account.id}")
|
||||
|
||||
if UpdateAccountService.new.call(@account, account_params)
|
||||
ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
|
||||
redirect_to settings_profile_path, notice: I18n.t('generic.changes_saved_msg')
|
||||
|
|
|
@ -33,6 +33,6 @@ module TextHelper
|
|||
end
|
||||
|
||||
def normalize_status(status)
|
||||
normalize_text("#{status.tags.pluck(:name).join(' ')}\n#{status.spoiler_text}\n#{status.local? ? Formatter.instance.format(status, skip_cache: true, cache: false) : status.text}\n#{status.media_attachments.pluck(:description).join("\n")}")
|
||||
normalize_text("#{status.tags.pluck(:name).join(' ')}\n#{status.spoiler_text}\n#{status.local? ? Formatter.instance.format(status) : status.text}\n#{status.media_attachments.pluck(:description).join("\n")}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,8 +30,6 @@ class Formatter
|
|||
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
CACHE_TIME = 1.hour
|
||||
|
||||
BBCODE_TAGS = {
|
||||
url: {
|
||||
html_open: '<a href="%url%" rel="noopener nofollow" target="_blank">', html_close: '</a>',
|
||||
|
@ -187,16 +185,6 @@ class Formatter
|
|||
}
|
||||
|
||||
def format(status, **options)
|
||||
unless options[:skip_cache]
|
||||
html = Rails.cache.fetch("formatted_status:#{status.id}")
|
||||
unless html.nil?
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
|
||||
return html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
end
|
||||
|
||||
orig_status = status
|
||||
|
||||
if status.reblog?
|
||||
prepend_reblog = status.reblog.account.acct
|
||||
status = status.proper
|
||||
|
@ -214,9 +202,6 @@ class Formatter
|
|||
|
||||
unless status.local?
|
||||
html = reformat(raw_content)
|
||||
|
||||
Rails.cache.write("formatted_status:#{orig_status.id}", html, expires_in: CACHE_TIME) unless options[:cache] == false
|
||||
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
|
||||
return html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
@ -237,7 +222,6 @@ class Formatter
|
|||
end
|
||||
|
||||
html = format_screenreader(html)
|
||||
|
||||
html = encode_and_link_urls(html, linkable_accounts, keep_html: %w(text/markdown text/x-bbcode text/x-bbcode+markdown text/html).include?(status.content_type))
|
||||
|
||||
if %w(text/markdown text/x-bbcode text/x-bbcode+markdown text/html).include?(status.content_type)
|
||||
|
@ -256,8 +240,6 @@ class Formatter
|
|||
html = "#{html.strip}\n<p class=\"signature\">— #{footer}</p>"
|
||||
end
|
||||
|
||||
Rails.cache.write("formatted_status:#{orig_status.id}", html, expires_in: CACHE_TIME) unless options[:cache] == false
|
||||
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
@ -296,20 +278,11 @@ class Formatter
|
|||
|
||||
def plaintext(status)
|
||||
return status.text if status.local?
|
||||
|
||||
text = status.text.gsub(/(<br \/>|<br>|<\/p>)+/) { |match| "#{match}\n" }
|
||||
strip_tags(text)
|
||||
end
|
||||
|
||||
def simplified_format(account, **options)
|
||||
unless options[:skip_cache]
|
||||
html = Rails.cache.fetch("formatted_account:#{account.id}")
|
||||
unless html.nil?
|
||||
html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if account.local? && options[:custom_emojify]
|
||||
return html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
end
|
||||
|
||||
if account.local?
|
||||
html = format_bbdown(account.note)
|
||||
html = encode_and_link_urls(html, keep_html: true)
|
||||
|
@ -318,8 +291,6 @@ class Formatter
|
|||
html = reformat(account.note)
|
||||
end
|
||||
|
||||
Rails.cache.write("formatted_account:#{account.id}", html, expires_in: CACHE_TIME) unless options[:cache] == false
|
||||
|
||||
html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if account.local? && options[:custom_emojify]
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
@ -329,52 +300,19 @@ class Formatter
|
|||
end
|
||||
|
||||
def format_spoiler(status, **options)
|
||||
unless options[:skip_cache]
|
||||
html = Rails.cache.fetch("formatted_spoiler:#{status.id}")
|
||||
unless html.nil?
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay])
|
||||
return html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
end
|
||||
|
||||
html = encode(status.spoiler_text)
|
||||
|
||||
Rails.cache.write("formatted_spoiler:#{status.id}", html, expires_in: CACHE_TIME) unless options[:cache] == false
|
||||
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay])
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
def format_poll_option(status, option, **options)
|
||||
unless options[:skip_cache]
|
||||
html = Rails.cache.fetch("formatted_poll:#{status.id}:#{option.id}")
|
||||
unless html.nil?
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay])
|
||||
return html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
end
|
||||
|
||||
html = encode(option.title)
|
||||
|
||||
Rails.cache.write("formatted_poll:#{status.id}:#{option.id}", html, expires_in: CACHE_TIME) unless options[:cache] == false
|
||||
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay])
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
def format_display_name(account, **options)
|
||||
unless options[:skip_cache]
|
||||
html = Rails.cache.fetch("formatted_display_name:#{account.id}")
|
||||
unless html.nil?
|
||||
html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if options[:custom_emojify]
|
||||
return html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
end
|
||||
|
||||
html = encode(account.display_name.presence || account.username)
|
||||
|
||||
Rails.cache.write("formatted_display_name:#{account.id}", html, expires_in: CACHE_TIME) unless options[:cache] == false
|
||||
|
||||
html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if options[:custom_emojify]
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
|
|
@ -341,7 +341,6 @@ class Status < ApplicationRecord
|
|||
after_create :process_bangtags, if: :local?
|
||||
|
||||
after_save :update_normalized_text
|
||||
after_save :formatter_remove_cached
|
||||
|
||||
class << self
|
||||
include SearchHelper
|
||||
|
@ -634,10 +633,6 @@ class Status < ApplicationRecord
|
|||
self.normalized_text = normalize_status(self)
|
||||
end
|
||||
|
||||
def formatter_remove_cached
|
||||
Rails.cache.delete("formatted_status:#{self.id}")
|
||||
end
|
||||
|
||||
def set_conversation
|
||||
self.thread = thread.reblog if thread&.reblog?
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
|||
end
|
||||
|
||||
def summary
|
||||
Formatter.instance.simplified_format(object, skip_cache: true)
|
||||
Formatter.instance.simplified_format(object)
|
||||
end
|
||||
|
||||
def icon
|
||||
|
|
|
@ -38,7 +38,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
|||
end
|
||||
|
||||
def content
|
||||
Formatter.instance.format(object, skip_cache: true)
|
||||
Formatter.instance.format(object)
|
||||
end
|
||||
|
||||
def source
|
||||
|
@ -48,7 +48,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
|||
end
|
||||
|
||||
def content_map
|
||||
{ object.language => Formatter.instance.format(object, skip_cache: true) }
|
||||
{ object.language => Formatter.instance.format(object) }
|
||||
end
|
||||
|
||||
def replies
|
||||
|
|
|
@ -68,8 +68,6 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
set_immediate_attributes!
|
||||
set_fetchable_attributes! unless @options[:only_keys]
|
||||
|
||||
Rails.cache.delete("formatted_account:#{@account.id}")
|
||||
|
||||
@account.save_with_optional_media!
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2019_11_18_084127) do
|
||||
ActiveRecord::Schema.define(version: 2019_11_18_102858) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_trgm"
|
||||
|
|
Loading…
Reference in New Issue