Update `account_summaries` database view

This commit is contained in:
Claire 2023-02-28 14:56:51 +01:00
parent f1cd809f72
commit 516053313e
3 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
class UpdateAccountSummariesToVersion3 < ActiveRecord::Migration[6.1]
def up
reapplication_global_follow_recommendations_v1 do
drop_view :account_summaries, materialized: true
create_view :account_summaries, version: 3, materialized: { no_data: true }
safety_assured { add_index :account_summaries, :account_id, unique: true }
end
end
def down
reapplication_global_follow_recommendations_v1 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 reapplication_global_follow_recommendations_v1
drop_view :global_follow_recommendations, materialized: true
yield
create_view :global_follow_recommendations, version: 1, materialized: { no_data: true }
safety_assured { add_index :global_follow_recommendations, :account_id, unique: true }
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_03_27_124057) do
ActiveRecord::Schema[7.1].define(version: 2024_03_27_145403) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -1450,7 +1450,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_03_27_124057) do
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))
WHERE ((accounts.suspended_at IS NULL) AND (accounts.deleted_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))
GROUP BY accounts.id;
SQL
add_index "account_summaries", ["account_id", "language", "sensitive"], name: "idx_on_account_id_language_sensitive_250461e1eb"

View File

@ -0,0 +1,24 @@
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.deleted_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