mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-09 18:51:38 +00:00
Drop unused indices
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.
This commit is contained in:
parent
21a81e1111
commit
b7e3d44756
2 changed files with 64 additions and 74 deletions
64
priv/repo/migrations/20240501190000_drop_unused_indexes.exs
Normal file
64
priv/repo/migrations/20240501190000_drop_unused_indexes.exs
Normal file
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue