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

Fix large files failing to load. #1224

Merged
merged 4 commits into from
May 17, 2018
Merged

Fix large files failing to load. #1224

merged 4 commits into from
May 17, 2018

Conversation

tech4him1
Copy link
Contributor

@tech4him1 tech4him1 commented Apr 3, 2018

- Summary

Fixes #1092. Allows files over 1MB to be fetched from GitHub's API.

- Test plan

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@verythorough
Copy link
Contributor

verythorough commented Apr 3, 2018

Deploy preview for netlify-cms-www ready!

Built with commit 57b9ebd

https://deploy-preview-1224--netlify-cms-www.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Apr 3, 2018

Deploy preview for cms-demo ready!

Built with commit 57b9ebd

https://deploy-preview-1224--cms-demo.netlify.com

if (cached) { return cached; }

if (sha) {
return this.getBlob(sha);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we fetch the file by path if the SHA is invalid?

Copy link
Contributor

Choose a reason for hiding this comment

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

Using the Contents API as a backup makes sense. I feel like there are edge cases like file name changes where this could cause confusion, but that seems pretty low risk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll need to go back and check -- I'm assuming that we can just check for a 404?

Copy link
Contributor Author

@tech4him1 tech4him1 May 15, 2018

Choose a reason for hiding this comment

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

Although GitHub doesn't seem to ever do GC -- an invalid blob would be really weird. It would likely mean we were hashing the file differently than GitHub was on the server-side, which shouldn't happen.

return cache.then((cached) => {
if (cached) { return cached; }

if (sha) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Benaiah I'm assuming if we know the SHA we should fetch by SHA first. Is that a problem at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless there's some benefit to using the Contents API, e.g. differences in the response object, fetching by SHA make sense to me.

const dir = path.split('/').slice(0, -1).join('/');
return this.listFiles(dir)
.then(files => files.find(file => file.path === path))
.then(file => this.getBlob(file.sha));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the case be handled where file is undefined? It should never happen because there is no pagination.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't happen, agreed.

@tech4him1 tech4him1 changed the title WIP: Fix large files failing to load. Fix large files failing to load. Apr 13, 2018
@erquhart
Copy link
Contributor

How on earth did I completely miss this PR?!

Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

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

Thanks for this, Caleb! Looks good to me 👍

if (cached) { return cached; }

return this.request(`${this.repoURL}/git/blobs/${sha}`, {
headers: { Accept: "application/vnd.github.VERSION.raw" },
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to drop this header as it's only documented for use with the Contents API (unless you experienced an issue that required it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is for use with the blobs API as well, see https://developer.github.com/v3/git/blobs/.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see it now 👍

if (cached) { return cached; }

if (sha) {
return this.getBlob(sha);
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the Contents API as a backup makes sense. I feel like there are edge cases like file name changes where this could cause confusion, but that seems pretty low risk.

return cache.then((cached) => {
if (cached) { return cached; }

if (sha) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless there's some benefit to using the Contents API, e.g. differences in the response object, fetching by SHA make sense to me.

const dir = path.split('/').slice(0, -1).join('/');
return this.listFiles(dir)
.then(files => files.find(file => file.path === path))
.then(file => this.getBlob(file.sha));
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't happen, agreed.

@erquhart erquhart merged commit 55a24a7 into master May 17, 2018
@erquhart erquhart deleted the 1092-large-files branch May 17, 2018 16:05
erquhart pushed a commit that referenced this pull request May 17, 2018
brianlmacdonald pushed a commit to brianlmacdonald/netlify-cms that referenced this pull request May 23, 2018
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.

Collections fail to load if any of the Github request is above 1mb
3 participants