about summary refs log tree commit diff
path: root/db/migrate
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-08-10 22:01:11 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:17 -0500
commit351b3819b29b316136553e1f88032a9df9a7a731 (patch)
tree9fae62b062ea4e8f819211d4bdc5ea08776b5388 /db/migrate
parent6b231291f90e494686e8ad696aede8dd0157cddf (diff)
[Database] Add indexes for published statuses and local reblogs
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20200811024642_update_status_indexes.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/db/migrate/20200811024642_update_status_indexes.rb b/db/migrate/20200811024642_update_status_indexes.rb
new file mode 100644
index 000000000..264f583a4
--- /dev/null
+++ b/db/migrate/20200811024642_update_status_indexes.rb
@@ -0,0 +1,23 @@
+class UpdateStatusIndexes < ActiveRecord::Migration[5.2]
+  def up
+    safety_assured do
+      add_index :statuses, ["id", "account_id"], name: "index_statuses_local", order: { id: :desc }, where: "((published = TRUE) AND (local = TRUE OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((reply = FALSE) OR (in_reply_to_account_id = account_id)))"
+      add_index :statuses, ["id", "account_id"], name: "index_statuses_public", order: { id: :desc }, where: "((published = TRUE) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((reply = FALSE) OR (in_reply_to_account_id = account_id)))"
+      add_index :statuses, ["id", "account_id"], name: "index_statuses_local_reblogs", where: "(((local = TRUE) OR (uri IS NULL)) AND (statuses.reblog_of_id IS NOT NULL))"
+
+      remove_index :statuses, name: "index_statuses_local_20190824"
+      remove_index :statuses, name: "index_statuses_public_20200119"
+    end
+  end
+
+  def down
+    safety_assured do
+      add_index :statuses, ["id", "account_id"], name: "index_statuses_local_20190824", order: { id: :desc }, where: "((local OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
+      add_index :statuses, ["id", "account_id"], name: "index_statuses_public_20200119", order: { id: :desc }, where: "((deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
+
+      remove_index :statuses, name: "index_statuses_local"
+      remove_index :statuses, name: "index_statuses_local_reblogs"
+      remove_index :statuses, name: "index_statuses_public"
+    end
+  end
+end