about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-12-16 16:19:28 +0100
committerClaire <claire.github-309c@sitedethib.com>2021-12-16 16:20:44 +0100
commitb2526316f54839968c821295e63066beaa425159 (patch)
treeb13a52c19923edfb80518f82ac060f296e68aeb2 /db
parentd911c17f521d6b13861caa886715a50b644007a1 (diff)
parent2aafa5b4e7a83ce8195cd739f1233a52ab060db7 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `app/views/admin/pending_accounts/index.html.haml`:
  Removed upstream, while it had glitch-soc-specific changes to accomodate
  for glitch-soc's theming system.
  Removed the file.

Additional changes:
- `app/views/admin/accounts/index.html.haml':
  Accomodate for glitch-soc's theming system.
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20211213040746_update_account_summaries_to_version_2.rb24
-rw-r--r--db/schema.rb4
-rw-r--r--db/views/account_summaries_v02.sql23
3 files changed, 49 insertions, 2 deletions
diff --git a/db/migrate/20211213040746_update_account_summaries_to_version_2.rb b/db/migrate/20211213040746_update_account_summaries_to_version_2.rb
new file mode 100644
index 000000000..0d1f092ec
--- /dev/null
+++ b/db/migrate/20211213040746_update_account_summaries_to_version_2.rb
@@ -0,0 +1,24 @@
+class UpdateAccountSummariesToVersion2 < ActiveRecord::Migration[6.1]
+  def up
+    reapplication_follow_recommendations_v2 do
+      drop_view :account_summaries, materialized: true
+      create_view :account_summaries, version: 2, materialized: { no_data: true }
+      safety_assured { add_index :account_summaries, :account_id, unique: true }
+    end
+  end
+
+  def down
+    reapplication_follow_recommendations_v2 do
+      drop_view :account_summaries, materialized: true
+      create_view :account_summaries, version: 1, materialized: { no_data: true }
+      safety_assured { add_index :account_summaries, :account_id, unique: true }
+    end
+  end
+
+  def reapplication_follow_recommendations_v2
+    drop_view :follow_recommendations, materialized: true
+    yield
+    create_view :follow_recommendations, version: 2, materialized: { no_data: true }
+    safety_assured { add_index :follow_recommendations, :account_id, unique: true }
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index edadeba1f..d3337ac04 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: 2021_11_26_000907) do
+ActiveRecord::Schema.define(version: 2021_12_13_040746) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -1131,7 +1131,7 @@ ActiveRecord::Schema.define(version: 2021_11_26_000907) do
               statuses.language,
               statuses.sensitive
              FROM statuses
-            WHERE ((statuses.account_id = accounts.id) AND (statuses.deleted_at IS NULL))
+            WHERE ((statuses.account_id = accounts.id) AND (statuses.deleted_at IS NULL) AND (statuses.reblog_of_id IS NULL))
             ORDER BY statuses.id DESC
            LIMIT 20) t0)
     WHERE ((accounts.suspended_at IS NULL) AND (accounts.silenced_at IS NULL) AND (accounts.moved_to_account_id IS NULL) AND (accounts.discoverable = true) AND (accounts.locked = false))
diff --git a/db/views/account_summaries_v02.sql b/db/views/account_summaries_v02.sql
new file mode 100644
index 000000000..17f5605f8
--- /dev/null
+++ b/db/views/account_summaries_v02.sql
@@ -0,0 +1,23 @@
+SELECT
+  accounts.id AS account_id,
+  mode() WITHIN GROUP (ORDER BY language ASC) AS language,
+  mode() WITHIN GROUP (ORDER BY sensitive ASC) AS sensitive
+FROM accounts
+CROSS JOIN LATERAL (
+  SELECT
+    statuses.account_id,
+    statuses.language,
+    statuses.sensitive
+  FROM statuses
+  WHERE statuses.account_id = accounts.id
+    AND statuses.deleted_at IS NULL
+    AND statuses.reblog_of_id IS NULL
+  ORDER BY statuses.id DESC
+  LIMIT 20
+) t0
+WHERE accounts.suspended_at IS NULL
+  AND accounts.silenced_at IS NULL
+  AND accounts.moved_to_account_id IS NULL
+  AND accounts.discoverable = 't'
+  AND accounts.locked = 'f'
+GROUP BY accounts.id