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

Refactor the code for the netlify functions #296

Merged

Conversation

theory-in-progress
Copy link
Contributor

Description

Fix #

Additional context

Refactoring some of the code


What is the purpose of this pull request?

  • Bug fix
  • New feature
  • Other

- Created the zipRes_Uid function to reuse in various places
@netlify
Copy link

netlify bot commented Aug 20, 2023

Deploy Preview for code-generator ready!

Name Link
🔨 Latest commit 311a1de
🔍 Latest deploy log https://app.netlify.com/sites/code-generator/deploys/64e46368fa35c800089f5a04
😎 Deploy Preview https://deploy-preview-296--code-generator.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 60 to 61
const nbUid = uuidv5(hash, uuidv5.URL)
const content = await zip.generateAsync({ type: 'base64' })
Copy link
Member

Choose a reason for hiding this comment

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

We can also produce the hash from the content instead of concatenated files with code. To see if this makes more interesting in terms of perfs. I suspect that content length could be smaller than the length of hash.
By the way, the name of variable hash is wrong as we do not create any hash with hash += code[filename].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is indeed smaller than concatenating the whole code. But I guess one thing I didn't understand while testing was that the content is different for the same template every time, without any modifications... I thought same code with the same files would generate the same zip.

So it's also generating a new Uid for each open in colab button press, which it should not for no code changes... This leads me to believe that zip being generated is slightly different every time. This creates a new uid each time, Which we wouldn't want. Ideally, we would like to keep the uid same for the template without any changes...

@guptaaryan16 since you've worked on this, do you have any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

@theory-in-progress @vfdev-5 Actually when we click on 'Open in Colab' or 'Download Zip', it makes an async request to the netlify functions to get the uuid for the code and the code link. I think we should create a store.js: uuid variable which gets updated to NULL whenever we make any changes in the store.config and these requests to netlify functions should be made only when store.uuid != NULL. Probably needs a fresh PR on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But these netlify functions are triggered only when we click on 'Open in Colab' or 'Download Zip'. And each time they are being for the changed code, we would like it to contain a new uuid. Also the gencode function is on watch for dynamic updates to the config so I'm unsure on how to set a global variable shared between the three files which would indicate that the config has been updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we can update the functions to take uuid parameter from store.js in NavCode and NavDownload such that the call to save template and make uuid request only happens when uuid != NULL otherwise it will just use the uuid and create a link using that itself. Also if config changes we can update the uuid = NULL

functions/utils.js Outdated Show resolved Hide resolved
Copy link
Member

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @theory-in-progress
Anything else needed here from your side or this PR can be merged ?

@theory-in-progress
Copy link
Contributor Author

It can be merged! Just have to write ci tests for checking this... Will do it in a new PR 👍

@theory-in-progress theory-in-progress merged commit 03b8d17 into pytorch-ignite:main Aug 22, 2023
20 checks passed
@theory-in-progress theory-in-progress deleted the refactor-zipRes branch August 29, 2023 04:45
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.

None yet

3 participants