diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-05-05 22:04:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-05 22:04:52 +0200 |
commit | d9ae3db8d5543cf0b7fa44186c191c9bb2472d23 (patch) | |
tree | 512309009b33d99557dbfbc7d2513b1b3792bf60 /db/migrate | |
parent | 351c74459084ccffce1333b57c2af9a6b55cac8d (diff) |
Improve performance of follow recommendation scheduler (#16159)
Express follow_recommendations in terms of account_summaries rather than accounts, integrate filters that are unconditionally used, and materialize the resulting view. This should result in the bulk of the computation being performed only once instead of **once per recommendation language**.
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb b/db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb new file mode 100644 index 000000000..9b2a284e4 --- /dev/null +++ b/db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb @@ -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: 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 |