Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use a stream when uploading database contents #1465

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 3 commits into from
Jan 9, 2023

Conversation

robertbrignull
Copy link
Contributor

Closes #1383

Instead of loading the entire database contents into memory, pass a ReadStream to request. Internally, octokit uses node-fetch and that is capable of accepting a stream. I then had to add the content length manually because the database upload API requires this header, but it wasn't populated when passing a stream to request.

Finally, I moved slightly more logic inside the try-catch. This should mean that if the database upload fails again for a user it won't block the main analysis and generally won't be an issue.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@robertbrignull robertbrignull requested a review from a team January 6, 2023 15:34
@robertbrignull robertbrignull requested a review from a team as a code owner January 6, 2023 15:34
@robertbrignull
Copy link
Contributor Author

I tested this in another repo and the database upload was successful.

@angelapwen
Copy link
Contributor

Hm, looks like there's a genuine unit test failure related to the Windows file system 👁️

@aeisenberg
Copy link
Contributor

Looks reasonable to me. @angelapwen is right. I wonder if you need to explicitly close the read stream before you can delete it.

@robertbrignull robertbrignull changed the title Robertbrignull/upload database stream Use a stream when uploading database contents Jan 9, 2023
Comment on lines +50 to +61
{
owner: repositoryNwo.owner,
repo: repositoryNwo.repo,
language,
name: `${language}-database`,
data: bundledDbReadStream,
headers: {
authorization: `token ${apiDetails.auth}`,
"Content-Type": "application/zip",
"Content-Length": bundledDbSize,
},
}

Check warning

Code scanning / CodeQL

File data in outbound network request

Outbound network request depends on [file data](1).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is intended and not changing behaviour in this PR

@robertbrignull
Copy link
Contributor Author

Thanks @angelapwen and @aeisenberg. I've added a finally block to close the stream. I'm glad we have those windows unit tests to catch this!

@robertbrignull robertbrignull merged commit 166d98c into main Jan 9, 2023
@robertbrignull robertbrignull deleted the robertbrignull/upload_database_stream branch January 9, 2023 12:37
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.

Support upload of large databases (> 2GB)
4 participants