Skip to content
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

feat: module collection #28

Merged
merged 9 commits into from
Dec 10, 2020
Merged

feat: module collection #28

merged 9 commits into from
Dec 10, 2020

Conversation

agazso
Copy link
Member

@agazso agazso commented Dec 8, 2020

This PR introduces the collection functionality, e.g. uploading multiple files and then accessing files from the collection.

I plan to not fix the issues with the Readable interface because I discovered that we may need to choose a different approach for the browser and it will most likely affect that as well. The issues with the browser are the following:

  • we are using tar-stream for creating the tar in a streaming way
  • it relies on dependencies that are not working in the browser
    • for example it uses buffer which is not polyfilled from version 5 of webpack (that is the version we use)
  • it relies also on readable-stream which relies on stream which is also not polyfilled
  • and the list goes on

I also found that the generated JS bundle for the browser is already quite big.

Based on our previous conversations I would suggest a different approach, to try to use browser APIs and polyfill them on Node.js. On the server side the size doesn't matter that much anyhow. For example using something like this:
https://github.com/MattiasBuelens/web-streams-polyfill

This would require more research and maybe changing some packages that we depend on now but I would keep it as a separate issue and not as part of this PR.

nugaon
nugaon previously requested changes Dec 9, 2020
Comment on lines 53 to 63
for (const entry of data) {
if (entry.data instanceof Uint8Array) {
tar.addUint8Array(entry.path, entry.data)
} else if (isReadable(entry.data)) {
if (entry.size === undefined) {
throw new BeeError(`Size has to be specified for Readable data! [${entry.path}]`)
}

tar.addStream(entry.path, entry.size, entry.data)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It seems ineffective for performance, because it continuously checks its type of the data, when it could be supposed from the first element of the data object

Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn't worry about performance here, because generally creating the tar and uploading it is orders of magnitude longer time than the check itself. Besides the code is now very straightforward and I don't really see how a change what you proposed could be implemented without casts.

Copy link
Member

Choose a reason for hiding this comment

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

I think the casting is okay if we can save plenty of unnecessary checkings in loops. You're right about this snippet in the whole process is not the most resource consumable task, but we should strive for the optimal running time at every function regardless the whole context.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't necessary agree to work on microoptimizations like this without measuring actual performance and seeing that it causes issues. Optimizations in general lead to less maintainable code.

Copy link
Member

Choose a reason for hiding this comment

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

In my opinion, this is not micro-optimization and also can be handled in a nice way.

@agazso agazso mentioned this pull request Dec 9, 2020
7 tasks
@agazso agazso marked this pull request as ready for review December 9, 2020 15:28
Copy link
Contributor

@vojtechsimetka vojtechsimetka left a comment

Choose a reason for hiding this comment

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

LGTM

*/
export async function upload(
url: string,
data: Collection<Uint8Array | Readable>,
Copy link
Contributor

@vojtechsimetka vojtechsimetka Dec 10, 2020

Choose a reason for hiding this comment

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

NOTE: For browsers I would love to have support for FormData and use Multipart upload. Not within a scope for this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm curious in which case you would prefer it over the FileList API (that we support).

https://developer.mozilla.org/en-US/docs/Web/API/FileList

Choose a reason for hiding this comment

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

NOTE: For browsers I would love to have support for FormData and use Multipart upload. Not within a scope for this PR

Hi, does Bee now support this? I'm struggling with missing Content-type errors

@agazso agazso dismissed nugaon’s stale review December 10, 2020 13:07

We discussed that we postpone this optimization for now

@agazso agazso merged commit e4ed0bd into master Dec 10, 2020
@agazso agazso deleted the feat/module-collection branch December 10, 2020 13:08
@agazso agazso mentioned this pull request Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants