aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-06-06 20:50:08 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-06-06 20:50:08 -1000
commite9b1ee71a12fcd6c15a2f0b06671bc819da98303 (patch)
tree96e8b009bca3e326285838e76295515ad6f2459a /lib/serve.js
parent4d96b6e0f7b726a5d96742e51fcb6c05b1d3f85f (diff)
downloadpatchfoo-e9b1ee71a12fcd6c15a2f0b06671bc819da98303.tar.gz
patchfoo-e9b1ee71a12fcd6c15a2f0b06671bc819da98303.zip
Don't call blobs.want if we already have the blob
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 59a09d5..1fe9b37 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -947,22 +947,18 @@ Serve.prototype.blob = function (id) {
var self = this
var blobs = self.app.sbot.blobs
if (self.req.headers['if-none-match'] === id) return self.respond(304)
- var done = multicb({pluck: 1, spread: true})
- blobs.want(id, function (err, has) {
+ self.app.wantSizeBlob(id, function (err, size) {
if (err) {
if (/^invalid/.test(err.message)) return self.respond(400, err.message)
else return self.respond(500, err.message || err)
}
- if (!has) return self.respond(404, 'Not found')
- blobs.size(id, done())
pull(
blobs.get(id),
pull.map(Buffer),
- ident(done().bind(self, null)),
+ ident(gotType),
self.respondSink()
)
- done(function (err, size, type) {
- if (err) console.trace(err)
+ function gotType(type) {
type = type && mime.lookup(type)
if (type) self.res.setHeader('Content-Type', type)
if (typeof size === 'number') self.res.setHeader('Content-Length', size)
@@ -971,7 +967,7 @@ Serve.prototype.blob = function (id) {
self.res.setHeader('Cache-Control', 'public, max-age=315360000')
self.res.setHeader('etag', id)
self.res.writeHead(200)
- })
+ }
})
}