mirror of
https://github.com/funamitech/mastodon
synced 2024-11-27 14:29:03 +09:00
Change materialized views to be refreshed concurrently to avoid locks (#29015)
This commit is contained in:
parent
c4af668e5c
commit
fa0ba67753
@ -19,6 +19,8 @@ class AccountSummary < ApplicationRecord
|
|||||||
scope :filtered, -> { where.missing(:follow_recommendation_suppressions) }
|
scope :filtered, -> { where.missing(:follow_recommendation_suppressions) }
|
||||||
|
|
||||||
def self.refresh
|
def self.refresh
|
||||||
|
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
|
||||||
|
rescue ActiveRecord::StatementInvalid
|
||||||
Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false)
|
Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ class FollowRecommendation < ApplicationRecord
|
|||||||
scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) }
|
scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) }
|
||||||
|
|
||||||
def self.refresh
|
def self.refresh
|
||||||
|
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
|
||||||
|
rescue ActiveRecord::StatementInvalid
|
||||||
Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false)
|
Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class CreateAccountSummaries < ActiveRecord::Migration[5.2]
|
class CreateAccountSummaries < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
create_view :account_summaries, materialized: { no_data: true }
|
create_view :account_summaries, materialized: true
|
||||||
|
|
||||||
# To be able to refresh the view concurrently,
|
# To be able to refresh the view concurrently,
|
||||||
# at least one unique index is required
|
# at least one unique index is required
|
||||||
|
@ -6,7 +6,7 @@ class UpdateFollowRecommendationsToVersion2 < ActiveRecord::Migration[6.1]
|
|||||||
|
|
||||||
def up
|
def up
|
||||||
drop_view :follow_recommendations
|
drop_view :follow_recommendations
|
||||||
create_view :follow_recommendations, version: 2, materialized: { no_data: true }
|
create_view :follow_recommendations, version: 2, materialized: true
|
||||||
|
|
||||||
# To be able to refresh the view concurrently,
|
# To be able to refresh the view concurrently,
|
||||||
# at least one unique index is required
|
# at least one unique index is required
|
||||||
|
@ -4,7 +4,7 @@ class UpdateAccountSummariesToVersion2 < ActiveRecord::Migration[6.1]
|
|||||||
def up
|
def up
|
||||||
reapplication_follow_recommendations_v2 do
|
reapplication_follow_recommendations_v2 do
|
||||||
drop_view :account_summaries, materialized: true
|
drop_view :account_summaries, materialized: true
|
||||||
create_view :account_summaries, version: 2, materialized: { no_data: true }
|
create_view :account_summaries, version: 2, materialized: true
|
||||||
safety_assured { add_index :account_summaries, :account_id, unique: true }
|
safety_assured { add_index :account_summaries, :account_id, unique: true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -12,7 +12,7 @@ class UpdateAccountSummariesToVersion2 < ActiveRecord::Migration[6.1]
|
|||||||
def down
|
def down
|
||||||
reapplication_follow_recommendations_v2 do
|
reapplication_follow_recommendations_v2 do
|
||||||
drop_view :account_summaries, materialized: true
|
drop_view :account_summaries, materialized: true
|
||||||
create_view :account_summaries, version: 1, materialized: { no_data: true }
|
create_view :account_summaries, version: 1, materialized: true
|
||||||
safety_assured { add_index :account_summaries, :account_id, unique: true }
|
safety_assured { add_index :account_summaries, :account_id, unique: true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -20,7 +20,7 @@ class UpdateAccountSummariesToVersion2 < ActiveRecord::Migration[6.1]
|
|||||||
def reapplication_follow_recommendations_v2
|
def reapplication_follow_recommendations_v2
|
||||||
drop_view :follow_recommendations, materialized: true
|
drop_view :follow_recommendations, materialized: true
|
||||||
yield
|
yield
|
||||||
create_view :follow_recommendations, version: 2, materialized: { no_data: true }
|
create_view :follow_recommendations, version: 2, materialized: true
|
||||||
safety_assured { add_index :follow_recommendations, :account_id, unique: true }
|
safety_assured { add_index :follow_recommendations, :account_id, unique: true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class CreateGlobalFollowRecommendations < ActiveRecord::Migration[7.0]
|
class CreateGlobalFollowRecommendations < ActiveRecord::Migration[7.0]
|
||||||
def change
|
def change
|
||||||
create_view :global_follow_recommendations, materialized: { no_data: true }
|
create_view :global_follow_recommendations, materialized: true
|
||||||
safety_assured { add_index :global_follow_recommendations, :account_id, unique: true }
|
safety_assured { add_index :global_follow_recommendations, :account_id, unique: true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ class DropFollowRecommendations < ActiveRecord::Migration[7.0]
|
|||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
create_view :follow_recommendations, version: 2, materialized: { no_data: true }
|
create_view :follow_recommendations, version: 2, materialized: true
|
||||||
safety_assured { add_index :follow_recommendations, :account_id, unique: true }
|
safety_assured { add_index :follow_recommendations, :account_id, unique: true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user