git ssb

3+

cel / ssb-npm-registry



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.jschanged
index.jsView
@@ -130,9 +130,11 @@
130130 cb(err, msg)
131131 })
132132 }
133133
134-function getDependencyBranches(sbot, id, cb) {
134 +function getDependencyBranches(sbot, link, cb) {
135 + var id = link.link
136 +
135137 // get ids of heads of tree of dependencyBranch message links to include all
136138 // the dependencies of the given tarball id.
137139 var getPackageJsonCached = memo(getPackageJsonFromTarballBlob, sbot)
138140 var msgs = {}
@@ -182,22 +184,48 @@
182184 var version = distTags[spec]
183185 || semver.maxSatisfying(Object.keys(versions), spec)
184186 var item = versions[version]
185187 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)
193189 // console.log('add', item.msg.key, item.mentionData.name, item.mentionData.version)
194190 addPkgById(item.mention.link, cb)
195191 })
196192 )
197193 }
198194
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) {
200228 if (err) return cb(err)
201229 var ids = []
202230 for (var key in msgs) {
203231 if (!branched[key]) ids.push(key)
@@ -222,52 +250,23 @@
222250 )
223251 }
224252
225253 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- )
252254 }
253255
254256 // For each dependency that is not a bundledDependency, get message ids for
255257 // that dependency name + version.
256258 function publishSingleMention(sbot, mention, cb) {
257259 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.
259261 var value = {
260262 type: 'npm-packages',
261263 mentions: [mention]
262264 }
263265 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) {
267267 if (err) return cb(err)
268- value.dependencyBranch = dependencyBranches || undefined
269- value.versionBranch = versionBranches || undefined
268 + value.dependencyBranch = branches || undefined
270269 publishMsg(sbot, value, cb)
271270 })
272271 }
273272
@@ -605,10 +604,9 @@
605604 if (!data.version) return
606605 if (data.distTag) {
607606 var tag = distTags[data.distTag]
608607 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 */
611609 distTags[data.distTag] = {ts: mention.ts, version: data.version}
612610 }
613611 }
614612 obj.versions[data.version] = {

Built with git-ssb-web