diff --git a/db/post_migrate/20240326231854_improve_preview_cards_vacuum.rb b/db/post_migrate/20240326231854_improve_preview_cards_vacuum.rb new file mode 100644 index 0000000000..a61c23ceef --- /dev/null +++ b/db/post_migrate/20240326231854_improve_preview_cards_vacuum.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class ImprovePreviewCardsVacuum < ActiveRecord::Migration[7.1] + disable_ddl_transaction! + + def change + add_index :preview_cards, :id, name: 'index_preview_cards_vacuum', where: "image_file_name IS NOT NULL AND image_file_name <> ''", algorithm: :concurrently + add_index :media_attachments, :id, name: 'index_media_attachments_vacuum', where: "file_file_name IS NOT NULL AND remote_url <> ''", algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index fa50276a7e..6c25607468 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[7.1].define(version: 2024_03_22_161611) do +ActiveRecord::Schema[7.1].define(version: 2024_03_26_231854) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -853,6 +853,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_03_22_161611) do t.datetime "thumbnail_updated_at", precision: nil t.string "thumbnail_remote_url" t.index ["account_id", "status_id"], name: "index_media_attachments_on_account_id_and_status_id", order: { status_id: :desc } + t.index ["id"], name: "index_media_attachments_vacuum", where: "((file_file_name IS NOT NULL) AND ((remote_url)::text <> ''::text))" t.index ["scheduled_status_id"], name: "index_media_attachments_on_scheduled_status_id", where: "(scheduled_status_id IS NOT NULL)" t.index ["shortcode"], name: "index_media_attachments_on_shortcode", unique: true, opclass: :text_pattern_ops, where: "(shortcode IS NOT NULL)" t.index ["status_id"], name: "index_media_attachments_on_status_id" @@ -1178,6 +1179,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_03_22_161611) do t.integer "link_type" t.datetime "published_at" t.string "image_description", default: "", null: false + t.index ["id"], name: "index_preview_cards_vacuum", where: "((image_file_name IS NOT NULL) AND ((image_file_name)::text <> ''::text))" t.index ["url"], name: "index_preview_cards_on_url", unique: true end diff --git a/lib/tasks/dangerous.rake b/lib/tasks/dangerous.rake index ae5e414171..9444559492 100644 --- a/lib/tasks/dangerous.rake +++ b/lib/tasks/dangerous.rake @@ -95,6 +95,7 @@ namespace :dangerous do 20240229233617 20240312230204 20240320231633 + 20240326231854 ) # Removed: account_groups target_tables = %w( @@ -177,6 +178,8 @@ namespace :dangerous do target_indices = %w( index_statuses_on_url index_statuses_on_conversation_id + index_preview_cards_vacuum + index_media_attachments_vacuum ) prompt.say 'Processing...'