]> cat aescling's git repositories - mastodon.git/commitdiff
Do not use WHERE NOT IN in CopyStatusStats migration (#8281)
authorEugen Rochko <eugen@zeonfederated.com>
Sun, 19 Aug 2018 00:01:49 +0000 (02:01 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Aug 2018 00:01:49 +0000 (02:01 +0200)
Fix #8275

As the batch operation progresses, the statuses_stats table grows,
and the WHERE NOT IN subquery becomes more expensive

db/migrate/20180812173710_copy_status_stats.rb

index 0c5907c301c7a147f6c3a09136efaf83b8b5e5f3..850aa9c13ee8274a961ae35debd6af2f3117a9af 100644 (file)
@@ -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