summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-28 12:55:29 +0100
committerErik Johnston <erik@matrix.org>2015-04-28 12:55:29 +0100
commita1d4813a54ad711d6db7da51f301412e3f139346 (patch)
treebcc0576250fb6f62afcf917cae66bc392d0492e1
parentUse TEXT instead of VARCHAR(n), since PostgreSQL treats them the same except ... (diff)
downloadsynapse-a1d4813a54ad711d6db7da51f301412e3f139346.tar.xz
Quickly fix dodgy est. time remaining
-rw-r--r--scripts/port_from_sqlite_to_postgres.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/scripts/port_from_sqlite_to_postgres.py b/scripts/port_from_sqlite_to_postgres.py
index a40a93ca76..b4ee860a92 100644
--- a/scripts/port_from_sqlite_to_postgres.py
+++ b/scripts/port_from_sqlite_to_postgres.py
@@ -535,11 +535,20 @@ class CursesProgress(Progress):
 
         self.finished = False
 
+        self.total_processed = 0
+        self.total_remaining = 0
+
         super(CursesProgress, self).__init__()
 
     def update(self, table, num_done):
         super(CursesProgress, self).update(table, num_done)
 
+        self.total_processed = 0
+        self.total_remaining = 0
+        for table, data in self.tables.items():
+            self.total_processed += data["num_done"] - data["start"]
+            self.total_remaining += data["total"] - data["num_done"]
+
         self.render()
 
     def render(self, force=False):
@@ -561,13 +570,11 @@ class CursesProgress(Progress):
         if self.finished:
             status = "Time spent: %s (Done!)" % (duration_str,)
         else:
-            min_perc = min(
-                (v["num_done"] - v["start"]) * 100. / (v["total"] - v["start"])
-                if v["total"] - v["start"] else 100
-                for v in self.tables.values()
-            )
-            if min_perc > 0:
-                est_remaining = (int(now) - self.start_time) * 100 / min_perc
+
+            if self.total_processed > 0:
+                left = float(self.total_remaining) / self.total_processed
+
+                est_remaining = (int(now) - self.start_time) * left
                 est_remaining_str = '%02dm %02ds remaining' % divmod(est_remaining, 60)
             else:
                 est_remaining_str = "Unknown"