diff options
author | rinpatch <rinpatch@sdf.org> | 2020-04-11 19:46:04 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-04-11 19:46:04 +0000 |
commit | 5e365448f3fed98da0395ad69c9325795a85a12d (patch) | |
tree | ca36ada03040bc1afb5a83db2dad481ff434f257 /priv | |
parent | c682563b92ce0b1a44523b67f5739707dd203de0 (diff) | |
parent | ea9c57b26ed463622e4489736fcddb8fca1b3341 (diff) | |
download | pleroma-5e365448f3fed98da0395ad69c9325795a85a12d.tar.gz pleroma-5e365448f3fed98da0395ad69c9325795a85a12d.zip |
Merge branch 'following-relationships-optimizations' into 'develop'
FollowingRelationship storage & performance optimizations
See merge request pleroma/pleroma!2332
Diffstat (limited to 'priv')
-rw-r--r-- | priv/repo/migrations/20200328124805_change_following_relationships_state_to_integer.exs | 29 | ||||
-rw-r--r-- | priv/repo/migrations/20200328130139_add_following_relationships_following_id_index.exs | 11 |
2 files changed, 40 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200328124805_change_following_relationships_state_to_integer.exs b/priv/repo/migrations/20200328124805_change_following_relationships_state_to_integer.exs new file mode 100644 index 000000000..2b0820f3f --- /dev/null +++ b/priv/repo/migrations/20200328124805_change_following_relationships_state_to_integer.exs @@ -0,0 +1,29 @@ +defmodule Pleroma.Repo.Migrations.ChangeFollowingRelationshipsStateToInteger do + use Ecto.Migration + + @alter_following_relationship_state "ALTER TABLE following_relationships ALTER COLUMN state" + + def up do + execute(""" + #{@alter_following_relationship_state} 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_following_relationship_state} TYPE varchar(255) USING + CASE + WHEN state = 1 THEN 'pending' + WHEN state = 2 THEN 'accept' + WHEN state = 3 THEN 'reject' + ELSE '' + END; + """) + end +end diff --git a/priv/repo/migrations/20200328130139_add_following_relationships_following_id_index.exs b/priv/repo/migrations/20200328130139_add_following_relationships_following_id_index.exs new file mode 100644 index 000000000..884832f84 --- /dev/null +++ b/priv/repo/migrations/20200328130139_add_following_relationships_following_id_index.exs @@ -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(index(:following_relationships, [:following_id])) + end +end |