Commit 8fe62bb65f2acf84e07a7284752d9d79e13e0903
Include latest previous versions in dependencyBranch
instead of in versionBranch. This reduces the number of messages that must be linked to in dependencyBranch, since usually the package shares many of the same dependencies as its previous version - so we can just link to the previous version to link transitively to those dependencies. versionBranch no longer will be included in new messages, as it is not needed anywhere. Future ssb-npm-registry releases could skip checking for versionBranch at all.cel committed on 6/30/2018, 8:57:26 PM
Parent: 8a4974fd8a7728b57aaa09d797b14fb065313500
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -130,9 +130,11 @@ | ||
130 | 130 … | cb(err, msg) |
131 | 131 … | }) |
132 | 132 … | } |
133 | 133 … | |
134 | -function getDependencyBranches(sbot, id, cb) { | |
134 … | +function getDependencyBranches(sbot, link, cb) { | |
135 … | + var id = link.link | |
136 … | + | |
135 | 137 … | // get ids of heads of tree of dependencyBranch message links to include all |
136 | 138 … | // the dependencies of the given tarball id. |
137 | 139 … | var getPackageJsonCached = memo(getPackageJsonFromTarballBlob, sbot) |
138 | 140 … | var msgs = {} |
@@ -182,22 +184,48 @@ | ||
182 | 184 … | var version = distTags[spec] |
183 | 185 … | || semver.maxSatisfying(Object.keys(versions), spec) |
184 | 186 … | var item = versions[version] |
185 | 187 … | if (!item) return cb(new Error('Dependency version not found: ' + name + '@' + spec)) |
186 | - msgs[item.msg.key] = item.msg.value | |
187 | - var c = item.msg.value.content | |
188 | - if (Array.isArray(c.dependencyBranch)) { | |
189 | - for (var k = 0; k < c.dependencyBranch.length; k++) { | |
190 | - branched[c.dependencyBranch[k]] = true | |
191 | - } | |
192 | - } | |
188 … | + addDepBranchMsg(item.msg) | |
193 | 189 … | // console.log('add', item.msg.key, item.mentionData.name, item.mentionData.version) |
194 | 190 … | addPkgById(item.mention.link, cb) |
195 | 191 … | }) |
196 | 192 … | ) |
197 | 193 … | } |
198 | 194 … | |
199 | - addPkgById(id, function (err) { | |
195 … | + function addDepBranchMsg(msg) { | |
196 … | + var c = msg && msg.value && msg.value.content | |
197 … | + if (!c) return | |
198 … | + if (msgs[msg.key]) return | |
199 … | + msgs[msg.key] = msg.value | |
200 … | + if (Array.isArray(c.dependencyBranch)) { | |
201 … | + for (var k = 0; k < c.dependencyBranch.length; k++) { | |
202 … | + branched[c.dependencyBranch[k]] = true | |
203 … | + } | |
204 … | + } | |
205 … | + if (Array.isArray(c.versionBranch)) { | |
206 … | + for (var k = 0; k < c.versionBranch.length; k++) { | |
207 … | + branched[c.versionBranch[k]] = true | |
208 … | + } | |
209 … | + } | |
210 … | + } | |
211 … | + | |
212 … | + function addPkgsByName(name, cb) { | |
213 … | + var data = decodeName(name) | |
214 … | + pull( | |
215 … | + getMentions(sbot.links2, {$prefix: 'npm:' + data.name + ':'}), | |
216 … | + pull.map(function (mention) { | |
217 … | + return packageLinks(sbot, mention.author, mention.link, data.name) | |
218 … | + }), | |
219 … | + pull.flatten(), | |
220 … | + pull.drain(addDepBranchMsg, cb) | |
221 … | + ) | |
222 … | + } | |
223 … | + | |
224 … | + var done = multicb() | |
225 … | + addPkgsByName(link.name, done()) | |
226 … | + addPkgById(id, done()) | |
227 … | + done(function (err) { | |
200 | 228 … | if (err) return cb(err) |
201 | 229 … | var ids = [] |
202 | 230 … | for (var key in msgs) { |
203 | 231 … | if (!branched[key]) ids.push(key) |
@@ -222,52 +250,23 @@ | ||
222 | 250 … | ) |
223 | 251 … | } |
224 | 252 … | |
225 | 253 … | function getVersionBranches(sbot, link, cb) { |
226 | - var data = decodeName(link.name) | |
227 | - var msgs = {}, branched = {} | |
228 | - pull( | |
229 | - getMentions(sbot.links2, {$prefix: 'npm:' + data.name + ':'}), | |
230 | - pull.map(function (mention) { | |
231 | - return packageLinks(sbot, mention.author, mention.link, data.name) | |
232 | - }), | |
233 | - pull.flatten(), | |
234 | - pull.drain(function (msg) { | |
235 | - var c = msg && msg.value && msg.value.content | |
236 | - if (!c) return | |
237 | - msgs[msg.key] = msg.value | |
238 | - if (Array.isArray(c.versionBranch)) { | |
239 | - for (var k = 0; k < c.versionBranch.length; k++) { | |
240 | - branched[c.versionBranch[k]] = true | |
241 | - } | |
242 | - } | |
243 | - }, function (err) { | |
244 | - if (err) return cb(err) | |
245 | - var ids = [] | |
246 | - for (var key in msgs) { | |
247 | - if (!branched[key]) ids.push(key) | |
248 | - } | |
249 | - cb(null, ids) | |
250 | - }) | |
251 | - ) | |
252 | 254 … | } |
253 | 255 … | |
254 | 256 … | // For each dependency that is not a bundledDependency, get message ids for |
255 | 257 … | // that dependency name + version. |
256 | 258 … | function publishSingleMention(sbot, mention, cb) { |
257 | 259 … | if (!sbot.links2) return cb(new Error('ssb-links scuttlebot plugin is required to publish ssb-npm packages')) |
258 | - // Calculate dependencyBranch and versionBranch message ids. | |
260 … | + // Calculate dependencyBranch message ids. | |
259 | 261 … | var value = { |
260 | 262 … | type: 'npm-packages', |
261 | 263 … | mentions: [mention] |
262 | 264 … | } |
263 | 265 … | var done = multicb({pluck: 1, spread: true}) |
264 | - getDependencyBranches(sbot, mention.link, done()) | |
265 | - getVersionBranches(sbot, mention, done()) | |
266 | - done(function (err, dependencyBranches, versionBranches) { | |
266 … | + getDependencyBranches(sbot, mention, function (err, branches) { | |
267 | 267 … | if (err) return cb(err) |
268 | - value.dependencyBranch = dependencyBranches || undefined | |
269 | - value.versionBranch = versionBranches || undefined | |
268 … | + value.dependencyBranch = branches || undefined | |
270 | 269 … | publishMsg(sbot, value, cb) |
271 | 270 … | }) |
272 | 271 … | } |
273 | 272 … | |
@@ -605,10 +604,9 @@ | ||
605 | 604 … | if (!data.version) return |
606 | 605 … | if (data.distTag) { |
607 | 606 … | var tag = distTags[data.distTag] |
608 | 607 … | if (!tag || mention.ts > tag.ts) { |
609 | - /* TODO: sort by causal order (versionBranch links) instead of just | |
610 | - * by timestamps */ | |
608 … | + /* TODO: sort by causal order instead of only by timestamps */ | |
611 | 609 … | distTags[data.distTag] = {ts: mention.ts, version: data.version} |
612 | 610 … | } |
613 | 611 … | } |
614 | 612 … | obj.versions[data.version] = { |
Built with git-ssb-web