Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: over eager preload #1693

Merged
merged 2 commits into from
Nov 5, 2018
Merged

fix: over eager preload #1693

merged 2 commits into from
Nov 5, 2018

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Nov 5, 2018

TLDR; Preload was sending preload requests for EVERY dag node of an added file. This is unnecessary as the preload request will recursively slurp down the entire graph. This PR fixes that behaviour.


Adding file(s) causes the preload module to preload any root nodes for the added content. It sends a HTTP request to preload for each root CID because the API on the preload nodes will fetch any children automatically. This greatly reduces the number of HTTP requests we have make when adding large files that are chunked into multiple nodes.

However, the issue was that the tests were checking that a CID had been requested for preload, not that it had been requested only once.

I was inspecting the debug output for preload because of the recent CORS issues we've been having and noticed that multiple preload requests for the same CID were being sent. Worse still, when adding large files, the child nodes were also being requested 😱

The issues are:

  1. ipfs.add causes object.get to be called for every file added. The issue with that is that object.get will also attempt to preload the CID you pass it.
  2. ipfs.add causes pin.add to be called for each root CID. This in turn causes dag.get to be called for every node in the graph. The issue with that is that dag.get will also attempt to preload the CID you pass it.

The solution in both cases is to tell object.get and pin.add in the context of ipfs.add to not preload the CIDs that they are passed.

I've augmented the tests to ensure that only one of the required CIDs is requested from the preload nodes and with that change and the fixes to the code the tests are now passing.

Preload was sending perload requests for EVERY dag node of an added file. This is unnecessary as the preload request will recursively slurp down the entire graph. This PR fixes that behaviour.

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
@ghost ghost assigned alanshaw Nov 5, 2018
@ghost ghost added the status/in-progress In progress label Nov 5, 2018
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

👍

@alanshaw alanshaw merged commit f14c20d into master Nov 5, 2018
@ghost ghost removed the status/in-progress In progress label Nov 5, 2018
@alanshaw alanshaw deleted the fix/over-eager-preload branch November 5, 2018 16:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants