From b7e3d44756bc0f192f37befcfb75991d7a287816 Mon Sep 17 00:00:00 2001 From: Oneric Date: Wed, 1 May 2024 23:01:28 +0200 Subject: [PATCH] Drop unused indices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This promotes and expands our existing optional migration. Based on usage statistics from several instances, see: https://akkoma.dev/AkkomaGang/akkoma/issues/764 activities_hosts is now retained after all since it’s essential for the "instance" query parameter of *oma’s public timeline to reliably work in a reasonable amount of time. (Although akkoma-fe has no support for this feature and apparently barely anyone uses it.) activities_actor_index was already dropped before in 20221211234352_remove_unused_indices; no need to drop it again. Birthday indices were introduced in pleroma starting with 20220116183110_add_birthday_to_users which is past the last common migration 20210416051708. --- .../20240501190000_drop_unused_indexes.exs | 64 ++++++++++++++++ .../20230422154018_drop_unused_indexes.exs | 74 ------------------- 2 files changed, 64 insertions(+), 74 deletions(-) create mode 100644 priv/repo/migrations/20240501190000_drop_unused_indexes.exs delete mode 100644 priv/repo/optional_migrations/20230422154018_drop_unused_indexes.exs diff --git a/priv/repo/migrations/20240501190000_drop_unused_indexes.exs b/priv/repo/migrations/20240501190000_drop_unused_indexes.exs new file mode 100644 index 000000000..fa5a5767b --- /dev/null +++ b/priv/repo/migrations/20240501190000_drop_unused_indexes.exs @@ -0,0 +1,64 @@ +defmodule Pleroma.Repo.Migrations.DropUnusedIndexes do + use Ecto.Migration + + def up do + # Leftovers from a late Pleroma migration (will not be restored on rollback) + drop_i(:users, [:show_birthday], :users_show_birthday_index) + + drop_i( + :users, + ["date_part('month', birthday)", "date_part('day', birthday)"], + :users_birthday_month_day_index + ) + + # Unused + drop_i(:activities, ["(data->'cc')"], :activities_cc_index) + drop_i(:activities, ["(data->'object'->>'inReplyTo')"], :activities_in_reply_to) + drop_i(:activities, ["(data #> '{\"object\",\"likes\"}')"], :activities_likes) + drop_i(:activities, ["(data->'to')"], :activities_to_index) + + drop_i(:objects, ["(data->'likes')"], :objects_likes) + + drop_i(:users, [:featured_address], :users_featured_address_index) + drop_i(:users, [:following_address], :users_following_address_index) + drop_i(:users, [:invisible], :users_invisible_index) + drop_i(:users, [:last_status_at], :users_last_status_at_index) + drop_i(:users, [:tags], :users_tags_index) + + drop_i(:apps, [:client_id, :client_secret], :apps_client_id_client_secret_index) + drop_i(:apps, [:user_id], :apps_user_id_index) + + # Duplicate of primary key index (will not be restored on rollback) + drop_i( + :user_frontend_setting_profiles, + [:user_id, :frontend_name, :profile_name], + :user_frontend_setting_profiles_user_id_frontend_name_profile_name_index + ) + end + + def down do + create_i(:activities, ["(data->'cc')"], :activities_cc_index, :gin) + create_i(:activities, ["(data->'object'->>'inReplyTo')"], :activities_in_reply_to) + create_i(:activities, ["(data #> '{\"object\",\"likes\"}')"], :activities_likes, :gin) + create_i(:activities, ["(data->'to')"], :activities_to_index, :gin) + + create_i(:objects, ["(data->'likes')"], :objects_likes, :gin) + + create_i(:users, [:featured_address], :users_featured_address_index) + create_i(:users, [:following_address], :users_following_address_index) + create_i(:users, [:invisible], :users_invisible_index) + create_i(:users, [:last_status_at], :users_last_status_at_index) + create_i(:users, [:tags], :users_tags_index, :gin) + + create_i(:apps, [:client_id, :client_secret], :apps_client_id_client_secret_index) + create_i(:apps, [:user_id], :apps_user_id_index) + end + + defp drop_i(table, fields, name) do + drop_if_exists(index(table, fields, name: name)) + end + + defp create_i(table, fields, name, type \\ :btree) do + create_if_not_exists(index(table, fields, name: name, using: type)) + end +end diff --git a/priv/repo/optional_migrations/20230422154018_drop_unused_indexes.exs b/priv/repo/optional_migrations/20230422154018_drop_unused_indexes.exs deleted file mode 100644 index d8acb1034..000000000 --- a/priv/repo/optional_migrations/20230422154018_drop_unused_indexes.exs +++ /dev/null @@ -1,74 +0,0 @@ -defmodule Pleroma.Repo.Migrations.DropUnusedIndexes do - use Ecto.Migration - - @disable_ddl_transaction true - - @disable_migration_lock true - - def up do - drop_if_exists( - index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index) - ) - - drop_if_exists(index(:activities, ["(data->'to')"], name: :activities_to_index)) - - drop_if_exists(index(:activities, ["(data->'cc')"], name: :activities_cc_index)) - - drop_if_exists(index(:activities, ["(split_part(actor, '/', 3))"], name: :activities_hosts)) - - drop_if_exists( - index(:activities, ["(data->'object'->>'inReplyTo')"], name: :activities_in_reply_to) - ) - - drop_if_exists( - index(:activities, ["((data #> '{\"object\",\"likes\"}'))"], name: :activities_likes) - ) - end - - def down do - create_if_not_exists( - index(:activities, ["(data->>'actor')", "inserted_at desc"], - name: :activities_actor_index, - concurrently: true - ) - ) - - create_if_not_exists( - index(:activities, ["(data->'to')"], - name: :activities_to_index, - using: :gin, - concurrently: true - ) - ) - - create_if_not_exists( - index(:activities, ["(data->'cc')"], - name: :activities_cc_index, - using: :gin, - concurrently: true - ) - ) - - create_if_not_exists( - index(:activities, ["(split_part(actor, '/', 3))"], - name: :activities_hosts, - concurrently: true - ) - ) - - create_if_not_exists( - index(:activities, ["(data->'object'->>'inReplyTo')"], - name: :activities_in_reply_to, - concurrently: true - ) - ) - - create_if_not_exists( - index(:activities, ["((data #> '{\"object\",\"likes\"}'))"], - name: :activities_likes, - using: :gin, - concurrently: true - ) - ) - end -end