Commit 1adfbb0b9d62d7df9d107cffe8ec8f8a8381b8dd
migration: switch to count based progress once total known
Matt McKegg committed on 6/17/2017, 9:01:54 AMParent: 3cfd9eef195bcaa471c606769c2341d6df7536dd
Files changed
legacy.js | changed |
legacy.js | ||
---|---|---|
@@ -65,8 +65,10 @@ | ||
65 | 65 | })) |
66 | 66 | |
67 | 67 | if(flumedb) { |
68 | 68 | var prog = {} |
69 | + var prog2 = {current: 0, start: 0, target: 0} | |
70 | + | |
69 | 71 | function one (opts, cb) { |
70 | 72 | pull( |
71 | 73 | db.createLogStream(opts), |
72 | 74 | pull.collect(function (err, ary) { |
@@ -77,8 +79,9 @@ | ||
77 | 79 | |
78 | 80 | function update (since) { |
79 | 81 | var start = (prog.start = prog.start ? prog.start : +since) |
80 | 82 | prog.current = +since |
83 | + prog2.current += 1 | |
81 | 84 | } |
82 | 85 | |
83 | 86 | one({reverse: true, limit: 1}, function (err, last) { |
84 | 87 | if(!last) ready() //empty legacy database. |
@@ -107,10 +110,22 @@ | ||
107 | 110 | }) |
108 | 111 | } |
109 | 112 | |
110 | 113 | function load(since) { |
114 | + // fast track for more accurate progress | |
111 | 115 | pull( |
112 | 116 | db.createLogStream({gt: since}), |
117 | + pull.drain(x => { | |
118 | + prog2.target += 1 | |
119 | + }, (err) => { | |
120 | + // now that we know how many total items, switch to prog2 | |
121 | + if (!err) flumedb.progress.migration = prog2 | |
122 | + }) | |
123 | + ) | |
124 | + | |
125 | + // actual upgrade | |
126 | + pull( | |
127 | + db.createLogStream({gt: since}), | |
113 | 128 | paramap(function (data, cb) { |
114 | 129 | update(data.timestamp) |
115 | 130 | flumedb.append(data, cb) |
116 | 131 | }, 32), |
@@ -122,5 +137,4 @@ | ||
122 | 137 | } |
123 | 138 | }) |
124 | 139 | } |
125 | 140 | } |
126 | - |
Built with git-ssb-web