diff options
-rw-r--r-- | app/controllers/settings/profiles_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/text_helper.rb | 2 | ||||
-rw-r--r-- | app/lib/formatter.rb | 62 | ||||
-rw-r--r-- | app/models/status.rb | 5 | ||||
-rw-r--r-- | app/serializers/activitypub/actor_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/activitypub/note_serializer.rb | 4 | ||||
-rw-r--r-- | app/services/activitypub/process_account_service.rb | 2 | ||||
-rw-r--r-- | db/schema.rb | 2 |
8 files changed, 5 insertions, 76 deletions
diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb index 183dcdcfc..6b3f0d311 100644 --- a/app/controllers/settings/profiles_controller.rb +++ b/app/controllers/settings/profiles_controller.rb @@ -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') diff --git a/app/helpers/text_helper.rb b/app/helpers/text_helper.rb index 5244fee8d..67ece4f32 100644 --- a/app/helpers/text_helper.rb +++ b/app/helpers/text_helper.rb @@ -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 diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 252532dc0..bdd372d3e 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -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 diff --git a/app/models/status.rb b/app/models/status.rb index 5f19eaff2..86b4f6bb2 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -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? diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb index 485d9d78f..7ea28afd5 100644 --- a/app/serializers/activitypub/actor_serializer.rb +++ b/app/serializers/activitypub/actor_serializer.rb @@ -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 diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb index fe943a472..ff39c97c4 100644 --- a/app/serializers/activitypub/note_serializer.rb +++ b/app/serializers/activitypub/note_serializer.rb @@ -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 diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 21f326988..a1d508405 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index bfb123aa3..63897a0e7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" |