From b8fb4b62515b8bdcfb1052df7d51afef0ba35966 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 17 Sep 2017 18:54:57 +0200 Subject: [PATCH] Delete invalid oEmbed caches with binary titles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are a few old oEmbed caches which have the title saved in binary (because they contain Chinese characters). This fails with `ActionView::Template::Error ("å" from ASCII-8BIT to UTF-8)`. Since I found only very old OEmbed caches with this problem (newest from 2012), I think we can just remove these. When I create a new oEmbed cache for the same URL it creates it without `!binary`. closes #7620 --- Changelog.md | 1 + .../20170917163640_cleanup_invalid_o_embed_caches.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 db/migrate/20170917163640_cleanup_invalid_o_embed_caches.rb diff --git a/Changelog.md b/Changelog.md index 0ccc9eb56..772876799 100644 --- a/Changelog.md +++ b/Changelog.md @@ -24,6 +24,7 @@ * Fix invalid data in the database for user data export [#7614](https://github.com/diaspora/diaspora/pull/7614) * Fix local migration run without old private key [#7558](https://github.com/diaspora/diaspora/pull/7558) * Fix export not downloadable because the filename was resetted on access [#7622](https://github.com/diaspora/diaspora/pull/7622) +* Delete invalid oEmbed caches with binary titles [#7620](https://github.com/diaspora/diaspora/pull/7620) ## Features * Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530) diff --git a/db/migrate/20170917163640_cleanup_invalid_o_embed_caches.rb b/db/migrate/20170917163640_cleanup_invalid_o_embed_caches.rb new file mode 100644 index 000000000..89272d2ff --- /dev/null +++ b/db/migrate/20170917163640_cleanup_invalid_o_embed_caches.rb @@ -0,0 +1,12 @@ +class CleanupInvalidOEmbedCaches < ActiveRecord::Migration[5.1] + class OEmbedCache < ApplicationRecord + end + class Post < ApplicationRecord + end + + def up + ids = OEmbedCache.where("data LIKE '%!binary%'").ids + Post.where(o_embed_cache_id: ids).update_all(o_embed_cache_id: nil) # rubocop:disable Rails/SkipsModelValidations + OEmbedCache.where(id: ids).delete_all + end +end