git ssb

30+

cel / git-ssb-web



Commit 0195a494a9de4868b88311db38de11d614b6da6d

Use pack index to help decode pack in update view

This improves performance
Charles Lehner committed on 4/5/2016, 4:24:56 AM
Parent: 0badbae079cf31c7da22f205cb2264254553d8c1

Files changed

index.jschanged
package.jsonchanged
index.jsView
@@ -1488,26 +1488,24 @@
14881488 cat(!msg.content.packs ? [] : [
14891489 pull.once('<h3>Commits</h3>'),
14901490 pull(
14911491 pull.values(msg.content.packs),
1492- paramap(function (pack, cb) {
1493- var key = pack.pack.link
1494- ssb.blobs.want(key, function (err, got) {
1495- if (err) cb(err)
1496- else if (!got) cb(null, pull.once('Missing blob ' + key))
1497- else cb(null, ssb.blobs.get(key))
1492+ pull.asyncMap(function (pack, cb) {
1493+ var done = multicb({ pluck: 1, spread: true })
1494+ getBlob(pack.pack.link, done())
1495+ getBlob(pack.idx.link, done())
1496+ done(function (err, readPack, readIdx) {
1497+ if (err) return cb(renderError(err))
1498+ cb(null, gitPack.decodeWithIndex(repo, readPack, readIdx))
14981499 })
1499- }, 8),
1500- pull.map(function (readPack, cb) {
1501- return gitPack.decode({}, repo, cb, readPack)
15021500 }),
15031501 pull.flatten(),
1504- paramap(function (obj, cb) {
1502+ pull.asyncMap(function (obj, cb) {
15051503 if (obj.type == 'commit')
15061504 Repo.getCommitParsed(obj, cb)
15071505 else
15081506 pull(obj.read, pull.drain(null, cb))
1509- }, 8),
1507+ }),
15101508 pull.filter(),
15111509 pull.map(function (commit) {
15121510 return renderCommit(repo, commit)
15131511 })
@@ -1601,15 +1599,21 @@
16011599 }
16021600 }
16031601 }
16041602
1603+ function getBlob(key, cb) {
1604+ ssb.blobs.want(key, function (err, got) {
1605+ if (err) cb(err)
1606+ else if (!got) cb(new Error('Missing blob ' + key))
1607+ else cb(null, ssb.blobs.get(key))
1608+ })
1609+ }
1610+
16051611 function serveBlob(req, key) {
1606- return readNext(function (cb) {
1607- ssb.blobs.want(key, function (err, got) {
1608- if (err) cb(null, serveError(err))
1609- else if (!got) cb(null, serve404(req))
1610- else cb(null, serveRaw()(ssb.blobs.get(key)))
1611- })
1612+ getBlob(key, function (err, read) {
1613+ if (err) cb(null, serveError(err))
1614+ else if (!got) cb(null, serve404(req))
1615+ else cb(null, serveRaw()(read))
16121616 })
16131617 }
16141618
16151619 /* Digs */
package.jsonView
@@ -8,9 +8,9 @@
88 "diff": "^2.2.2",
99 "highlight.js": "^9.2.0",
1010 "multicb": "^1.2.1",
1111 "pull-cat": "^1.1.8",
12- "pull-git-pack": "^0.1.2",
12+ "pull-git-pack": "^0.2.0",
1313 "pull-git-repo": "^0.3.2",
1414 "pull-paramap": "^1.1.2",
1515 "pull-stream": "^3.1.0",
1616 "ssb-client": "^3.0.1",

Built with git-ssb-web