git ssb

3+

cel / ssb-npm-registry



Commit c3bbc64337a05050c56c05fd27a96f63ce372f80

Add slow blob/message notice

cel committed on 11/29/2019, 9:06:26 PM
Parent: 6e231fbd601498d17cb3c66e71568e201211a3de

Files changed

README.mdchanged
index.jschanged
README.mdView
@@ -66,8 +66,12 @@
6666 These are resolved to message ids when the snippet is served. Default: `["scuttlebot", "ssb-npm", "git-ssb"]`
6767 - `config.npm.postInstallCmd`: Command string for the bootstrap snippet to run
6868 after installing packages, if any. Default: `"sbot server"`
6969
70 +### Environmental variables
71 +
72 +- `WANT_WARN_TIME`: duration (ms) to wait for a blob or ooo-msg want before outputting a warning about it to stderr. Default: 60000 (1 minute). If set to a negative value, no such warnings are output.
73 +
7074 ## API
7175
7276 ```
7377 var Registry = require('ssb-npm-registry')
index.jsView
@@ -77,8 +77,10 @@
7777 host = host.replace(/^::ffff:/, '')
7878 return host[0] !== '[' && /:.*:/.test(host) ? '[' + host + ']' : host
7979 }
8080
81 +var wantWarnTime = Number(process.env.WANT_WARN_TIME) || 60e3
82 +
8183 exports.name = 'npm-registry'
8284 exports.version = '1.0.0'
8385 exports.manifest = {
8486 getAddress: 'async'
@@ -381,10 +383,14 @@
381383 function getBlob(sbot, id, cb) {
382384 var blobs = sbot.blobs
383385 blobs.size(id, function (err, size) {
384386 if (err && err.code !== 'ENOENT') return cb(err)
385- if (typeof size === 'number') cb(null, blobs.get(id), size)
386- else blobs.want(id, function (err, got) {
387 + if (typeof size === 'number') return cb(null, blobs.get(id), size)
388 + var timeout = wantWarnTime > 0 && setTimeout(function () {
389 + console.error('Blob taking a long time to fetch:', id)
390 + }, wantWarnTime)
391 + blobs.want(id, function (err, got) {
392 + if (timeout) clearTimeout(timeout)
387393 if (err) cb(err)
388394 else if (!got) cb('missing blob ' + id)
389395 else blobs.size(id, function (err, size) {
390396 if (err) return cb(err)
@@ -427,9 +433,17 @@
427433 return getMentions(this.sbot.links2, name)
428434 }
429435
430436 SsbNpmRegistryServer.prototype.getMsg = function (id, cb) {
431- if (this.sbot.ooo) return this.sbot.ooo.get({id: id, timeout: 0}, cb)
437 + if (this.sbot.ooo) {
438 + var timeout = wantWarnTime > 0 && setTimeout(function () {
439 + console.error('Message taking a long time to fetch:', id)
440 + }, wantWarnTime)
441 + return this.sbot.ooo.get({id: id, timeout: 0}, timeout ? function (err, msg) {
442 + clearTimeout(timeout)
443 + cb(err, msg)
444 + } : cb)
445 + }
432446 else this.sbot.get(id, function (err, value) {
433447 if (err) console.error('Unable to get message:', id)
434448 if (err) return cb(err)
435449 cb(null, {key: id, value: value})

Built with git-ssb-web