Browse Source

Remove progress estimate from MigrateAccountConversations (#9168)

Eugen Rochko 1 month ago
parent
commit
f2290e311b
No account linked to committer's email address
1 changed files with 6 additions and 24 deletions
  1. 6
    24
      db/migrate/20181024224956_migrate_account_conversations.rb

+ 6
- 24
db/migrate/20181024224956_migrate_account_conversations.rb View File

@@ -14,17 +14,15 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
14 14
       sleep 1
15 15
     end
16 16
 
17
-    total        = estimate_rows(local_direct_statuses) + estimate_rows(notifications_about_direct_statuses)
18
-    migrated     = 0
19
-    started_time = Time.zone.now
20
-    last_time    = Time.zone.now
17
+    migrated  = 0
18
+    last_time = Time.zone.now
21 19
 
22 20
     local_direct_statuses.includes(:account, mentions: :account).find_each do |status|
23 21
       AccountConversation.add_status(status.account, status)
24 22
       migrated += 1
25 23
 
26 24
       if Time.zone.now - last_time > 1
27
-        say_progress(migrated, total, started_time)
25
+        say_progress(migrated)
28 26
         last_time = Time.zone.now
29 27
       end
30 28
     end
@@ -34,7 +32,7 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
34 32
       migrated += 1
35 33
 
36 34
       if Time.zone.now - last_time > 1
37
-        say_progress(migrated, total, started_time)
35
+        say_progress(migrated)
38 36
         last_time = Time.zone.now
39 37
       end
40 38
     end
@@ -45,24 +43,8 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
45 43
 
46 44
   private
47 45
 
48
-  def estimate_rows(query)
49
-    result = exec_query("EXPLAIN #{query.to_sql}").first
50
-    result['QUERY PLAN'].scan(/ rows=([\d]+)/).first&.first&.to_i || 0
51
-  end
52
-
53
-  def say_progress(migrated, total, started_time)
54
-    status = "Migrated #{migrated} rows"
55
-
56
-    percentage = 100.0 * migrated / total
57
-    status += " (~#{sprintf('%.2f', percentage)}%, "
58
-
59
-    remaining_time = (100.0 - percentage) * (Time.zone.now - started_time) / percentage
60
-
61
-    status += "#{(remaining_time / 60).to_i}:"
62
-    status += sprintf('%02d', remaining_time.to_i % 60)
63
-    status += ' remaining)'
64
-
65
-    say status, true
46
+  def say_progress(migrated)
47
+    say "Migrated #{migrated} rows", true
66 48
   end
67 49
 
68 50
   def local_direct_statuses