git ssb

1+

Dominic / secure-scuttlebutt



Commit 1adfbb0b9d62d7df9d107cffe8ec8f8a8381b8dd

migration: switch to count based progress once total known

Matt McKegg committed on 6/17/2017, 9:01:54 AM
Parent: 3cfd9eef195bcaa471c606769c2341d6df7536dd

Files changed

legacy.jschanged
legacy.jsView
@@ -65,8 +65,10 @@
6565 }))
6666
6767 if(flumedb) {
6868 var prog = {}
69+ var prog2 = {current: 0, start: 0, target: 0}
70+
6971 function one (opts, cb) {
7072 pull(
7173 db.createLogStream(opts),
7274 pull.collect(function (err, ary) {
@@ -77,8 +79,9 @@
7779
7880 function update (since) {
7981 var start = (prog.start = prog.start ? prog.start : +since)
8082 prog.current = +since
83+ prog2.current += 1
8184 }
8285
8386 one({reverse: true, limit: 1}, function (err, last) {
8487 if(!last) ready() //empty legacy database.
@@ -107,10 +110,22 @@
107110 })
108111 }
109112
110113 function load(since) {
114+ // fast track for more accurate progress
111115 pull(
112116 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}),
113128 paramap(function (data, cb) {
114129 update(data.timestamp)
115130 flumedb.append(data, cb)
116131 }, 32),
@@ -122,5 +137,4 @@
122137 }
123138 })
124139 }
125140 }
126-

Built with git-ssb-web