Merge commit 'dbb26586d891d81b264657d3686286366f6567c6' into glitch-soc/merge-upstream

This commit is contained in:
Claire committed 2026-08-05 18:17:49 +02:00
commit 20cece6e6e
17 files changed
+289 -446

No files matched your search

@@ -3,7 +3,7 @@
class CreateGeneratedAnnualReports < ActiveRecord::Migration[7.1]
def change
create_table :generated_annual_reports do |t|
t.belongs_to :account, null: false, foreign_key: { on_cascade: :delete }, index: false
t.belongs_to :account, null: false, foreign_key: true, index: false
t.integer :year, null: false
t.jsonb :data, null: false
t.integer :schema_version, null: false
@@ -0,0 +1,15 @@
# frozen_string_literal: true
class FixGeneratedAnnualReportsForeignKey < ActiveRecord::Migration[8.1]
def up
safety_assured do
execute 'ALTER TABLE generated_annual_reports DROP CONSTRAINT fk_rails_4ca37f035c, ADD CONSTRAINT fk_rails_4ca37f035c FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE;'
end
end
def down
safety_assured do
execute 'ALTER TABLE generated_annual_reports DROP CONSTRAINT fk_rails_4ca37f035c, ADD CONSTRAINT fk_rails_4ca37f035c FOREIGN KEY (account_id) REFERENCES accounts(id);'
end
end
end
@@ -0,0 +1,58 @@
# frozen_string_literal: true
class ConvertMaterializedViewsToTables < ActiveRecord::Migration[8.1]
def up
# Prepare replacement of `account_summaries`
rename_index :account_summaries, :index_account_summaries_on_account_id, :tmp_index_account_summaries_on_account_id
rename_index :account_summaries, :idx_on_account_id_language_sensitive_250461e1eb, :tmp_idx_on_account_id_language_sensitive_250461e1eb
# Create replacement table for `account_summaries`
create_table :tmp_account_summaries, primary_key: :account_id do |t| # rubocop:disable Rails/CreateTableWithTimestamps
t.string :language
t.boolean :sensitive, default: false, null: false
end
safety_assured do # The table is empty, so blocking is minimal
add_foreign_key :tmp_account_summaries, :accounts, on_delete: :cascade
add_index :tmp_account_summaries, [:account_id, :language, :sensitive], name: :idx_on_account_id_language_sensitive_250461e1eb
end
# Create replacement table for `global_follow_recommendations`
rename_index :global_follow_recommendations, :index_global_follow_recommendations_on_account_id, :tmp_index_global_follow_recommendations_on_account_id
create_table :tmp_global_follow_recommendations, primary_key: :account_id do |t| # rubocop:disable Rails/CreateTableWithTimestamps
t.decimal :rank, null: false
t.string :reason, array: true, null: false
t.boolean :stale, null: false, default: false
end
safety_assured do # The table is empty, so blocking is minimal
add_foreign_key :tmp_global_follow_recommendations, :accounts, on_delete: :cascade
add_index :tmp_global_follow_recommendations, :rank, name: :index_global_follow_recommendations_on_rank
end
# Fill the tables
safety_assured do
execute 'INSERT INTO tmp_account_summaries SELECT account_summaries.* FROM account_summaries INNER JOIN accounts ON accounts.id = account_summaries.account_id' if Scenic.database.populated?('account_summaries')
execute 'INSERT INTO tmp_global_follow_recommendations SELECT global_follow_recommendations.* FROM global_follow_recommendations INNER JOIN accounts ON accounts.id = global_follow_recommendations.account_id' if Scenic.database.populated?('global_follow_recommendations')
end
# Drop and rename
drop_view :global_follow_recommendations, materialized: true
safety_assured { rename_table :tmp_global_follow_recommendations, :global_follow_recommendations }
drop_view :account_summaries, materialized: true
safety_assured { rename_table :tmp_account_summaries, :account_summaries }
end
def down
drop_table :account_summaries
create_view :account_summaries, version: 3, materialized: true
add_index :account_summaries, :account_id, unique: true
add_index :account_summaries, [:account_id, :language, :sensitive]
drop_table :global_follow_recommendations
create_view :global_follow_recommendations, version: 1, materialized: true
add_index :global_follow_recommendations, :account_id, unique: true
end
end
+17 -52
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_08_03_172525) do
ActiveRecord::Schema[8.1].define(version: 2026_08_05_130216) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@@ -130,6 +130,12 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_03_172525) do
t.index ["account_id"], name: "index_account_statuses_cleanup_policies_on_account_id"
end
create_table "account_summaries", primary_key: "account_id", force: :cascade do |t|
t.string "language"
t.boolean "sensitive", default: false, null: false
t.index ["account_id", "language", "sensitive"], name: "idx_on_account_id_language_sensitive_250461e1eb"
end
create_table "account_warning_presets", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.text "text", default: "", null: false
@@ -660,6 +666,13 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_03_172525) do
t.index ["account_id", "year"], name: "index_generated_annual_reports_on_account_id_and_year", unique: true
end
create_table "global_follow_recommendations", primary_key: "account_id", force: :cascade do |t|
t.decimal "rank", null: false
t.string "reason", null: false, array: true
t.boolean "stale", default: false, null: false
t.index ["rank"], name: "index_global_follow_recommendations_on_rank"
end
create_table "identities", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.string "provider", default: "", null: false
@@ -1487,6 +1500,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_03_172525) do
add_foreign_key "account_relationship_severance_events", "relationship_severance_events", on_delete: :cascade
add_foreign_key "account_stats", "accounts", on_delete: :cascade
add_foreign_key "account_statuses_cleanup_policies", "accounts", on_delete: :cascade
add_foreign_key "account_summaries", "accounts", on_delete: :cascade
add_foreign_key "account_warnings", "accounts", column: "target_account_id", on_delete: :cascade
add_foreign_key "account_warnings", "accounts", on_delete: :nullify
add_foreign_key "account_warnings", "reports", on_delete: :cascade
@@ -1540,7 +1554,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_03_172525) do
add_foreign_key "follow_requests", "accounts", name: "fk_76d644b0e7", on_delete: :cascade
add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade
add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade
add_foreign_key "generated_annual_reports", "accounts"
add_foreign_key "generated_annual_reports", "accounts", on_delete: :cascade
add_foreign_key "global_follow_recommendations", "accounts", on_delete: :cascade
add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade
add_foreign_key "instance_moderation_notes", "accounts", on_delete: :cascade
add_foreign_key "invites", "users", on_delete: :cascade
@@ -1625,56 +1640,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_03_172525) do
add_foreign_key "web_settings", "users", name: "fk_11910667b2", on_delete: :cascade
add_foreign_key "webauthn_credentials", "users", on_delete: :cascade
create_view "account_summaries", materialized: true, sql_definition: <<-SQL
SELECT accounts.id AS account_id,
mode() WITHIN GROUP (ORDER BY t0.language) AS language,
mode() WITHIN GROUP (ORDER BY t0.sensitive) 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.requested_deletion_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"
add_index "account_summaries", ["account_id"], name: "index_account_summaries_on_account_id", unique: true
create_view "global_follow_recommendations", materialized: true, sql_definition: <<-SQL
SELECT account_id,
sum(rank) AS rank,
array_agg(reason) AS reason
FROM ( SELECT account_summaries.account_id,
((count(follows.id))::numeric / (1.0 + (count(follows.id))::numeric)) AS rank,
'most_followed'::text AS reason
FROM ((follows
JOIN account_summaries ON ((account_summaries.account_id = follows.target_account_id)))
JOIN users ON ((users.account_id = follows.account_id)))
WHERE ((users.current_sign_in_at >= (now() - 'P30D'::interval)) AND (account_summaries.sensitive = false) AND (NOT (EXISTS ( SELECT 1
FROM follow_recommendation_suppressions
WHERE (follow_recommendation_suppressions.account_id = follows.target_account_id)))))
GROUP BY account_summaries.account_id
HAVING (count(follows.id) >= 5)
UNION ALL
SELECT account_summaries.account_id,
(sum((status_stats.reblogs_count + status_stats.favourites_count)) / (1.0 + sum((status_stats.reblogs_count + status_stats.favourites_count)))) AS rank,
'most_interactions'::text AS reason
FROM ((status_stats
JOIN statuses ON ((statuses.id = status_stats.status_id)))
JOIN account_summaries ON ((account_summaries.account_id = statuses.account_id)))
WHERE ((statuses.id >= (((date_part('epoch'::text, (now() - 'P30D'::interval)) * (1000)::double precision))::bigint << 16)) AND (account_summaries.sensitive = false) AND (NOT (EXISTS ( SELECT 1
FROM follow_recommendation_suppressions
WHERE (follow_recommendation_suppressions.account_id = statuses.account_id)))))
GROUP BY account_summaries.account_id
HAVING (sum((status_stats.reblogs_count + status_stats.favourites_count)) >= (5)::numeric)) t0
GROUP BY account_id
ORDER BY (sum(rank)) DESC;
SQL
add_index "global_follow_recommendations", ["account_id"], name: "index_global_follow_recommendations_on_account_id", unique: true
create_view "instances", materialized: true, sql_definition: <<-SQL
WITH domain_counts(domain, accounts_count) AS (
SELECT accounts.domain,