about summary refs log tree commit diff
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
parent6b231291f90e494686e8ad696aede8dd0157cddf (diff)
[Database] Add indexes for published statuses and local reblogs
-rw-r--r--db/migrate/20200811024642_update_status_indexes.rb23
-rw-r--r--db/schema.rb7
2 files changed, 27 insertions, 3 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
diff --git a/db/schema.rb b/db/schema.rb
index 4875e4e67..7d3ec26d7 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2020_08_01_220000) do
+ActiveRecord::Schema.define(version: 2020_08_11_024642) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -874,9 +874,10 @@ ActiveRecord::Schema.define(version: 2020_08_01_220000) do
     t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
     t.index ["account_id", "id"], name: "index_unpublished_statuses", order: { id: :desc }, where: "((deleted_at IS NULL) AND (published = false))"
     t.index ["conversation_id"], name: "index_statuses_on_conversation_id", where: "(deleted_at IS NULL)"
-    t.index ["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)))"
+    t.index ["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)))"
+    t.index ["id", "account_id"], name: "index_statuses_local_reblogs", where: "(((local = true) OR (uri IS NULL)) AND (reblog_of_id IS NOT NULL))"
     t.index ["id", "account_id"], name: "index_statuses_on_id_and_account_id"
-    t.index ["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)))"
+    t.index ["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)))"
     t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
     t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
     t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id"