summaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-08-19 02:01:49 +0200
committerGitHub <noreply@github.com>2018-08-19 02:01:49 +0200
commitf13afa1ee92ceb40ce2e44f6457bd6e75b80adb5 (patch)
treef1e6ae6caa23a5f56a2ea7259dbf32e7911809c2 /db
parent0fc0980de1d8b9fd94da5aa4ce5f222f57649eff (diff)
Do not use WHERE NOT IN in CopyStatusStats migration (#8281)
Fix #8275 As the batch operation progresses, the statuses_stats table grows, and the WHERE NOT IN subquery becomes more expensive
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180812173710_copy_status_stats.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/db/migrate/20180812173710_copy_status_stats.rb b/db/migrate/20180812173710_copy_status_stats.rb
index 0c5907c301c..850aa9c13ee 100644
--- a/db/migrate/20180812173710_copy_status_stats.rb
+++ b/db/migrate/20180812173710_copy_status_stats.rb
@@ -3,7 +3,7 @@ class CopyStatusStats < ActiveRecord::Migration[5.2]
def up
safety_assured do
- Status.where.not(id: StatusStat.select('status_id')).select('id').find_in_batches do |statuses|
+ Status.unscoped.select('id').find_in_batches(batch_size: 5_000) do |statuses|
execute <<-SQL.squish
INSERT INTO status_stats (status_id, reblogs_count, favourites_count, created_at, updated_at)
SELECT id, reblogs_count, favourites_count, created_at, updated_at