-
Notifications
You must be signed in to change notification settings - Fork 20
fix(exporter): add some parallel fetching of blocks where possible #73
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,40 @@ | |
|
||
const path = require('path') | ||
const pull = require('pull-stream') | ||
const paramap = require('pull-paramap') | ||
|
||
const fileExporter = require('./file') | ||
const switchType = require('../util').switchType | ||
|
||
// Logic to export a unixfs directory. | ||
module.exports = (node, name, dagService) => { | ||
// The algorithm below is as follows | ||
// | ||
// 1. Take all links from a given directory node | ||
// 2. Map each link to their full name (parent + link name) + hash | ||
// 3. Parallel map to | ||
// 3.1. Resolve the hash against the dagService | ||
// 3.2. Switch on the node type | ||
// - `directory`: return node | ||
// - `file`: use the fileExporter to load and return the file | ||
// 4. Flatten | ||
return pull( | ||
pull.values(node.links), | ||
pull.map((link) => ({ | ||
path: path.join(name, link.name), | ||
hash: link.hash | ||
})), | ||
pull.map((item) => pull( | ||
dagService.getStream(item.hash), | ||
pull.map((n) => switchType( | ||
paramap((item, cb) => dagService.get(item.hash, (err, n) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
|
||
cb(null, switchType( | ||
n, | ||
() => pull.values([item]), | ||
() => fileExporter(n, item.path, dagService) | ||
)), | ||
pull.flatten() | ||
)), | ||
)) | ||
})), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dignifiedquire could you please add a bit of documentation to this function, each time I come to read it, I scratch my head to get back to understand what is supposed to be going on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no. If is helpful to have diagrams, add a file to explain the internals with those graphs :) The unixfs-engine is a big piece of the files API and it needs to be easy to understand and pluggable so that we can extend it easily with other layouts, customs chunkers and so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @diasdavid added a description. Can we get this merged soon plese? |
||
pull.flatten() | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3