FollowingRelationship storage & performance optimizations (state turned ecto_enum-driven integer, reorganized indices etc.).

This commit is contained in:
Ivan Tashkinov 2020-03-28 18:49:03 +03:00
commit be9d18461a
17 changed files with 128 additions and 45 deletions

View file

@ -0,0 +1,29 @@
defmodule Pleroma.Repo.Migrations.ChangeFollowingRelationshipsStateToInteger do
use Ecto.Migration
@alter_apps_scopes "ALTER TABLE following_relationships ALTER COLUMN state"
def up do
execute("""
#{@alter_apps_scopes} TYPE integer USING
CASE
WHEN state = 'pending' THEN 1
WHEN state = 'accept' THEN 2
WHEN state = 'reject' THEN 3
ELSE 0
END;
""")
end
def down do
execute("""
#{@alter_apps_scopes} TYPE varchar(255) USING
CASE
WHEN state = 1 THEN 'pending'
WHEN state = 2 THEN 'accept'
WHEN state = 3 THEN 'reject'
ELSE ''
END;
""")
end
end

View file

@ -0,0 +1,11 @@
defmodule Pleroma.Repo.Migrations.AddFollowingRelationshipsFollowingIdIndex do
use Ecto.Migration
# [:follower_index] index is useless because of [:follower_id, :following_id] index
# [:following_id] index makes sense because of user's followers-targeted queries
def change do
drop_if_exists(index(:following_relationships, [:follower_id]))
create_if_not_exists(drop_if_exists(index(:following_relationships, [:following_id])))
end
end