Skip to content

refactor: use the block API from ipfs instead of ipld internals #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2020

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Apr 16, 2020

This improves reusability of the module as it can be used by passing part of an ipfs or ipfs-http-client instance in.

It also means we no longer double serialize blocks before adding them which delivers a very small performance increase (1-2%).

Finally also documents the pin and preload arguments.

BREAKING CHANGE:

The importer takes a pin argument (previously undocumented) - it used to default to true but since this switches to use the block API the default has changed to false, as the typical usage pattern is to pin the root block of a DAG recursively instead of every block that makes up the DAG.

This improves resusability of the module as it can be used by passing
part of an `ipfs` or `ipfs-http-client` instance in.

It also means we no longer double-serialize blocks before adding them
which delivers a small but almost unperceptible performance increase.

Finally also documents the `pin` and `preload` arguments.
@achingbrain achingbrain requested a review from hugomrdias April 16, 2020 07:54
Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change!


module.exports = (ipld) => {
// make ipld behave like the block api, some tests need to pull
// data from ipld so can't use use a simple hash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "use use"

Also I don't really understand this comment :) What is a simple hash (a multihash instead of a CID?)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An overloaded term, sorry - hash as in hash table, not hash as in multihash. I've updated the comments.

@@ -25,15 +25,15 @@ const defaultOptions = {
maxChildrenPerNode: 174,
layerRepeat: 4,
wrapWithDirectory: false,
pin: true,
pin: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just double checking if that's intended or a left-over from debugging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we switched to the block API from the IPLD API, the pinning should be done by the caller after they are done importing, because you typically want the root CID pinned recursively (e.g. 1x pin), rather than each block pinned (e.g. potentially many pins).


module.exports = (ipld) => {
// make ipld behave like the block api, some tests need to pull
// data from ipld so can't use use a simple hash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same as for the exporter)

typo: "use use"

Also I don't really understand this comment :) What is a simple hash (a multihash instead of a CID?)?

@achingbrain achingbrain merged commit cfecf39 into master Apr 23, 2020
@achingbrain achingbrain deleted the feat/use-block-api branch April 23, 2020 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants