summaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-03-28 18:49:03 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-03-28 18:49:03 +0300
commitbe9d18461a5ed6bd835e2eba8d3b54ba61fc51fb (patch)
tree0b5b199feab5cef526d365030213170c99fb9f0f /priv
parent4e81b4b190161ebb0c496c682fa8e1e0c38a3903 (diff)
downloadpleroma-be9d18461a5ed6bd835e2eba8d3b54ba61fc51fb.tar.gz
pleroma-be9d18461a5ed6bd835e2eba8d3b54ba61fc51fb.zip
FollowingRelationship storage & performance optimizations (state turned `ecto_enum`-driven integer, reorganized indices etc.).
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200328124805_change_following_relationships_state_to_integer.exs29
-rw-r--r--priv/repo/migrations/20200328130139_add_following_relationships_following_id_index.exs11
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..d5a431c00
--- /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_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
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..4c9faf48f
--- /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(drop_if_exists(index(:following_relationships, [:following_id])))
+ end
+end