Merge branch 'main' into glitch-soc/merge-upstream
- `app/views/statuses/_simple_status.html.haml`: Small markup change in glitch-soc, on a line that has been modified by upstream. Ported upstream changes.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class CreateAccountSummaries < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_view :account_summaries, materialized: true
|
||||
create_view :account_summaries, materialized: { no_data: true }
|
||||
|
||||
# To be able to refresh the view concurrently,
|
||||
# at least one unique index is required
|
||||
|
@@ -0,0 +1,13 @@
|
||||
class AddCaseInsensitiveBtreeIndexToTags < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower_btree ON tags (lower(name) text_pattern_ops)' }
|
||||
remove_index :tags, name: 'index_tags_on_name_lower'
|
||||
end
|
||||
|
||||
def down
|
||||
safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))' }
|
||||
remove_index :tags, name: 'index_tags_on_name_lower_btree'
|
||||
end
|
||||
end
|
@@ -0,0 +1,13 @@
|
||||
class AddIndexOnMediaAttachmentsAccountIdStatusId < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
add_index :media_attachments, [:account_id, :status_id], order: { status_id: :desc }, algorithm: :concurrently
|
||||
remove_index :media_attachments, :account_id, algorithm: :concurrently
|
||||
end
|
||||
|
||||
def down
|
||||
add_index :media_attachments, :account_id, algorithm: :concurrently
|
||||
remove_index :media_attachments, [:account_id, :status_id], order: { status_id: :desc }, algorithm: :concurrently
|
||||
end
|
||||
end
|
@@ -0,0 +1,18 @@
|
||||
class UpdateFollowRecommendationsToVersion2 < ActiveRecord::Migration[6.1]
|
||||
# We're switching from a normal to a materialized view so we need
|
||||
# custom `up` and `down` paths.
|
||||
|
||||
def up
|
||||
drop_view :follow_recommendations
|
||||
create_view :follow_recommendations, version: 2, materialized: { no_data: true }
|
||||
|
||||
# To be able to refresh the view concurrently,
|
||||
# at least one unique index is required
|
||||
safety_assured { add_index :follow_recommendations, :account_id, unique: true }
|
||||
end
|
||||
|
||||
def down
|
||||
drop_view :follow_recommendations, materialized: true
|
||||
create_view :follow_recommendations, version: 1
|
||||
end
|
||||
end
|
13
db/post_migrate/20210502233513_drop_account_tag_stats.rb
Normal file
13
db/post_migrate/20210502233513_drop_account_tag_stats.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DropAccountTagStats < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
drop_table :account_tag_stats
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
42
db/schema.rb
42
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_04_16_200740) do
|
||||
ActiveRecord::Schema.define(version: 2021_05_05_174616) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -115,15 +115,6 @@ ActiveRecord::Schema.define(version: 2021_04_16_200740) do
|
||||
t.index ["account_id"], name: "index_account_stats_on_account_id", unique: true
|
||||
end
|
||||
|
||||
create_table "account_tag_stats", force: :cascade do |t|
|
||||
t.bigint "tag_id", null: false
|
||||
t.bigint "accounts_count", default: 0, null: false
|
||||
t.boolean "hidden", default: false, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["tag_id"], name: "index_account_tag_stats_on_tag_id", unique: true
|
||||
end
|
||||
|
||||
create_table "account_warning_presets", force: :cascade do |t|
|
||||
t.text "text", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
@@ -541,7 +532,7 @@ ActiveRecord::Schema.define(version: 2021_04_16_200740) do
|
||||
t.integer "thumbnail_file_size"
|
||||
t.datetime "thumbnail_updated_at"
|
||||
t.string "thumbnail_remote_url"
|
||||
t.index ["account_id"], name: "index_media_attachments_on_account_id"
|
||||
t.index ["account_id", "status_id"], name: "index_media_attachments_on_account_id_and_status_id", order: { status_id: :desc }
|
||||
t.index ["scheduled_status_id"], name: "index_media_attachments_on_scheduled_status_id"
|
||||
t.index ["shortcode"], name: "index_media_attachments_on_shortcode", unique: true
|
||||
t.index ["status_id"], name: "index_media_attachments_on_status_id"
|
||||
@@ -864,7 +855,7 @@ ActiveRecord::Schema.define(version: 2021_04_16_200740) do
|
||||
t.datetime "last_status_at"
|
||||
t.float "max_score"
|
||||
t.datetime "max_score_at"
|
||||
t.index "lower((name)::text)", name: "index_tags_on_name_lower", unique: true
|
||||
t.index "lower((name)::text) text_pattern_ops", name: "index_tags_on_name_lower_btree", unique: true
|
||||
end
|
||||
|
||||
create_table "tombstones", force: :cascade do |t|
|
||||
@@ -987,7 +978,6 @@ ActiveRecord::Schema.define(version: 2021_04_16_200740) do
|
||||
add_foreign_key "account_pins", "accounts", column: "target_account_id", on_delete: :cascade
|
||||
add_foreign_key "account_pins", "accounts", on_delete: :cascade
|
||||
add_foreign_key "account_stats", "accounts", on_delete: :cascade
|
||||
add_foreign_key "account_tag_stats", "tags", 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 "accounts", "accounts", column: "moved_to_account_id", on_delete: :nullify
|
||||
@@ -1116,30 +1106,34 @@ ActiveRecord::Schema.define(version: 2021_04_16_200740) do
|
||||
SQL
|
||||
add_index "account_summaries", ["account_id"], name: "index_account_summaries_on_account_id", unique: true
|
||||
|
||||
create_view "follow_recommendations", sql_definition: <<-SQL
|
||||
create_view "follow_recommendations", materialized: true, sql_definition: <<-SQL
|
||||
SELECT t0.account_id,
|
||||
sum(t0.rank) AS rank,
|
||||
array_agg(t0.reason) AS reason
|
||||
FROM ( SELECT accounts.id AS account_id,
|
||||
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 accounts ON ((accounts.id = follows.target_account_id)))
|
||||
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 (accounts.suspended_at IS NULL) AND (accounts.moved_to_account_id IS NULL) AND (accounts.silenced_at IS NULL) AND (accounts.locked = false) AND (accounts.discoverable = true))
|
||||
GROUP BY accounts.id
|
||||
LEFT JOIN follow_recommendation_suppressions ON ((follow_recommendation_suppressions.account_id = follows.target_account_id)))
|
||||
WHERE ((users.current_sign_in_at >= (now() - 'P30D'::interval)) AND (account_summaries.sensitive = false) AND (follow_recommendation_suppressions.id IS NULL))
|
||||
GROUP BY account_summaries.account_id
|
||||
HAVING (count(follows.id) >= 5)
|
||||
UNION ALL
|
||||
SELECT accounts.id AS account_id,
|
||||
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
|
||||
FROM (((status_stats
|
||||
JOIN statuses ON ((statuses.id = status_stats.status_id)))
|
||||
JOIN accounts ON ((accounts.id = statuses.account_id)))
|
||||
WHERE ((statuses.id >= (((date_part('epoch'::text, (now() - 'P30D'::interval)) * (1000)::double precision))::bigint << 16)) AND (accounts.suspended_at IS NULL) AND (accounts.moved_to_account_id IS NULL) AND (accounts.silenced_at IS NULL) AND (accounts.locked = false) AND (accounts.discoverable = true))
|
||||
GROUP BY accounts.id
|
||||
JOIN account_summaries ON ((account_summaries.account_id = statuses.account_id)))
|
||||
LEFT JOIN follow_recommendation_suppressions ON ((follow_recommendation_suppressions.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 (follow_recommendation_suppressions.id IS NULL))
|
||||
GROUP BY account_summaries.account_id
|
||||
HAVING (sum((status_stats.reblogs_count + status_stats.favourites_count)) >= (5)::numeric)) t0
|
||||
GROUP BY t0.account_id
|
||||
ORDER BY (sum(t0.rank)) DESC;
|
||||
SQL
|
||||
add_index "follow_recommendations", ["account_id"], name: "index_follow_recommendations_on_account_id", unique: true
|
||||
|
||||
end
|
||||
|
34
db/views/follow_recommendations_v02.sql
Normal file
34
db/views/follow_recommendations_v02.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
SELECT
|
||||
account_id,
|
||||
sum(rank) AS rank,
|
||||
array_agg(reason) AS reason
|
||||
FROM (
|
||||
SELECT
|
||||
account_summaries.account_id AS account_id,
|
||||
count(follows.id) / (1.0 + count(follows.id)) AS rank,
|
||||
'most_followed' AS reason
|
||||
FROM follows
|
||||
INNER JOIN account_summaries ON account_summaries.account_id = follows.target_account_id
|
||||
INNER JOIN users ON users.account_id = follows.account_id
|
||||
LEFT OUTER JOIN follow_recommendation_suppressions ON follow_recommendation_suppressions.account_id = follows.target_account_id
|
||||
WHERE users.current_sign_in_at >= (now() - interval '30 days')
|
||||
AND account_summaries.sensitive = 'f'
|
||||
AND follow_recommendation_suppressions.id IS NULL
|
||||
GROUP BY account_summaries.account_id
|
||||
HAVING count(follows.id) >= 5
|
||||
UNION ALL
|
||||
SELECT account_summaries.account_id AS account_id,
|
||||
sum(reblogs_count + favourites_count) / (1.0 + sum(reblogs_count + favourites_count)) AS rank,
|
||||
'most_interactions' AS reason
|
||||
FROM status_stats
|
||||
INNER JOIN statuses ON statuses.id = status_stats.status_id
|
||||
INNER JOIN account_summaries ON account_summaries.account_id = statuses.account_id
|
||||
LEFT OUTER JOIN follow_recommendation_suppressions ON follow_recommendation_suppressions.account_id = statuses.account_id
|
||||
WHERE statuses.id >= ((date_part('epoch', now() - interval '30 days') * 1000)::bigint << 16)
|
||||
AND account_summaries.sensitive = 'f'
|
||||
AND follow_recommendation_suppressions.id IS NULL
|
||||
GROUP BY account_summaries.account_id
|
||||
HAVING sum(reblogs_count + favourites_count) >= 5
|
||||
) t0
|
||||
GROUP BY account_id
|
||||
ORDER BY rank DESC
|
Reference in New Issue
Block a user