Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
perf: fixes #97 by not sorting DAGNode links when they are already so…
Browse files Browse the repository at this point in the history
…rted
  • Loading branch information
achingbrain committed Oct 30, 2018
1 parent fb365de commit f003847
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,25 @@ function deserialize (data, callback) {

const buf = pbn.Data == null ? Buffer.alloc(0) : Buffer.from(pbn.Data)

DAGNode.create(buf, links, callback)
// Work out the CID that was used to load this node
// Will be inaccurate if the hash-alg was not the default sha2-256
// Should be able to go away when https://github.com/ipld/js-ipld/issues/173 is resolved
serialize({
data: buf,
links
}, (err, serialized) => {
if (err) {
return callback(err)
}

multihashing(serialized, 'sha2-256', (err, multihash) => {
if (err) {
return callback(err)
}

callback(null, new DAGNode(buf, links, serialized, multihash))
})
})
}

function toProtoBuf (node) {
Expand Down

0 comments on commit f003847

Please sign in to comment.