about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-09-20 22:52:50 -0500
committerFire Demon <firedemon@creature.cafe>2020-09-20 23:07:30 -0500
commit64694de343737360e797a92a0a6c0e88695facda (patch)
treee31a8d7eb5cb909be89df96e8185b20183ed5a22 /db
parente3cb18ba7520997a0f605c7f90db258ccccd5e33 (diff)
Monsterfork v1-style curated Federated timeline
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20200921024447_add_curated_to_statuses.rb7
-rw-r--r--db/migrate/20200921030158_backfill_curated_statuses.rb12
-rw-r--r--db/migrate/20200923000000_update_status_indexes_202009.rb25
-rw-r--r--db/schema.rb9
4 files changed, 49 insertions, 4 deletions
diff --git a/db/migrate/20200921024447_add_curated_to_statuses.rb b/db/migrate/20200921024447_add_curated_to_statuses.rb
new file mode 100644
index 000000000..05558ded3
--- /dev/null
+++ b/db/migrate/20200921024447_add_curated_to_statuses.rb
@@ -0,0 +1,7 @@
+class AddCuratedToStatuses < ActiveRecord::Migration[5.2]
+  def change
+    safety_assured do
+      add_column :statuses, :curated, :boolean, default: false, null: false
+    end
+  end
+end
diff --git a/db/migrate/20200921030158_backfill_curated_statuses.rb b/db/migrate/20200921030158_backfill_curated_statuses.rb
new file mode 100644
index 000000000..f9bf32afb
--- /dev/null
+++ b/db/migrate/20200921030158_backfill_curated_statuses.rb
@@ -0,0 +1,12 @@
+class BackfillCuratedStatuses < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    Status.with_public_visibility.joins(:status_stat).where('favourites_count != 0 OR reblogs_count != 0').in_batches.update_all(curated: true)
+    Status.with_public_visibility.where(curated: false).left_outer_joins(:bookmarks).where.not(bookmarks: { status_id: nil }).in_batches.update_all(curated: true)
+  end
+
+  def down
+    nil
+  end
+end
diff --git a/db/migrate/20200923000000_update_status_indexes_202009.rb b/db/migrate/20200923000000_update_status_indexes_202009.rb
new file mode 100644
index 000000000..9b6f58d3c
--- /dev/null
+++ b/db/migrate/20200923000000_update_status_indexes_202009.rb
@@ -0,0 +1,25 @@
+class UpdateStatusIndexes202009 < ActiveRecord::Migration[5.2]
+  def up
+    safety_assured do
+      remove_index :statuses, name: "index_statuses_local"
+      remove_index :statuses, name: "index_statuses_local_reblogs"
+      remove_index :statuses, name: "index_statuses_public"
+
+      add_index :statuses, :id, name: "index_statuses_local", order: { id: :desc }, where: "(published = TRUE) AND (local = TRUE OR (uri IS NULL)) AND (deleted_at IS NULL)"
+      add_index :statuses, :id, name: "index_statuses_curated", order: { id: :desc }, where: "(published = TRUE) AND (deleted_at IS NULL) AND (curated = TRUE)"
+      add_index :statuses, :id, name: "index_statuses_public", order: { id: :desc }, where: "(published = TRUE) AND (deleted_at IS NULL)"
+    end
+  end
+
+  def down
+    safety_assured do
+      remove_index :statuses, name: "index_statuses_local"
+      remove_index :statuses, name: "index_statuses_curated"
+      remove_index :statuses, name: "index_statuses_public"
+
+      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_local_reblogs", where: "(((local = TRUE) OR (uri IS NULL)) AND (statuses.reblog_of_id IS NOT NULL))"
+      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)))"
+    end
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index eb0605314..7a5411d1c 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_09_20_084007) do
+ActiveRecord::Schema.define(version: 2020_09_21_030158) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -883,14 +883,15 @@ ActiveRecord::Schema.define(version: 2020_09_20_084007) do
     t.datetime "expires_at"
     t.datetime "publish_at"
     t.boolean "originally_local_only", default: false, null: false
+    t.boolean "curated", default: false, null: false
     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 ["expires_at"], name: "index_statuses_on_expires_at", where: "(expires_at IS NOT NULL)"
-    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", 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 ["id"], name: "index_statuses_curated", order: :desc, where: "((published = true) AND (deleted_at IS NULL) AND (curated = true))"
+    t.index ["id"], name: "index_statuses_local", order: :desc, where: "((published = true) AND ((local = true) OR (uri IS NULL)) AND (deleted_at IS NULL))"
+    t.index ["id"], name: "index_statuses_public", order: :desc, where: "((published = true) AND (deleted_at IS NULL))"
     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 ["publish_at"], name: "index_statuses_on_publish_at", where: "(publish_at IS NOT NULL)"