Commit eb053658d95d72c0e99e5f92e1cb6794d99f7c44
call fn with same `this` context in hooked function. emit "replicate:finish" to fit tested api. make sure sequence defaults to 0
Dominic Tarr committed on 10/3/2016, 3:59:50 AMParent: e5d0b7d8bace9ec48ab12ec7a1a40872a050acad
Files changed
plugins/replicate.js | changed |
plugins/replicate.js | ||
---|---|---|
@@ -82,8 +82,11 @@ | ||
82 | 82 … | var seq = upto.sequence || upto.seq |
83 | 83 … | to_recv[upto.id] = Math.max(to_recv[upto.id] || 0, seq) |
84 | 84 … | if(this._emit) this._emit('call:createHistoryStream', args[0]) |
85 | 85 … | |
86 … | + //if we are calling this locally, skip cleverness | |
87 … | + if(this===sbot) return fn.call(this, upto) | |
88 … | + | |
86 | 89 … | debounce.set() |
87 | 90 … | |
88 | 91 … | //handle creating lots of histor streams efficiently. |
89 | 92 … | //maybe this could be optimized in map-filter-reduce queries instead? |
@@ -98,9 +101,9 @@ | ||
98 | 101 … | pushable.push(p) |
99 | 102 … | pushable.sequence = upto.sequence |
100 | 103 … | return p |
101 | 104 … | } |
102 | - return fn(upto) | |
105 … | + return fn.call(this, upto) | |
103 | 106 … | }) |
104 | 107 … | |
105 | 108 … | // collect the IDs of feeds we want to request |
106 | 109 … | var opts = config.replication || {} |
@@ -172,26 +175,26 @@ | ||
172 | 175 … | |
173 | 176 … | sbot.on('rpc:connect', function(rpc) { |
174 | 177 … | // this is the cli client, just ignore. |
175 | 178 … | if(rpc.id === sbot.id) return |
176 | - | |
177 | 179 … | //check for local peers, or manual connections. |
178 | 180 … | localPeers() |
179 | 181 … | var drain |
180 | 182 … | sbot.emit('replicate:start', rpc) |
181 | - | |
183 … | + rpc.on('closed', function () { | |
184 … | + sbot.emit('replicate:finish', to_send) | |
185 … | + }) | |
182 | 186 … | var SYNC = false |
183 | 187 … | pull( |
184 | 188 … | upto({live: opts.live}), |
185 | 189 … | drain = pull.drain(function (upto) { |
186 | 190 … | if(upto.sync) return |
187 | - | |
188 | 191 … | feeds++ |
189 | 192 … | debounce.set() |
190 | 193 … | pull( |
191 | 194 … | rpc.createHistoryStream({ |
192 | 195 … | id: upto.id, |
193 | - seq: (upto.sequence || upto.seq) + 1, | |
196 … | + seq: (upto.sequence || upto.seq || 0) + 1, | |
194 | 197 … | live: true, |
195 | 198 … | keys: false |
196 | 199 … | }), |
197 | 200 … | sbot.createWriteStream(function (err) { |
@@ -216,4 +219,11 @@ | ||
216 | 219 … | } |
217 | 220 … | } |
218 | 221 … | |
219 | 222 … | |
223 … | + | |
224 … | + | |
225 … | + | |
226 … | + | |
227 … | + | |
228 … | + | |
229 … | + |
Built with git-ssb-web