-
Notifications
You must be signed in to change notification settings - Fork 24
Refactor the code for the netlify functions #296
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
Conversation
- Created the zipRes_Uid function to reuse in various places
✅ Deploy Preview for code-generator ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
functions/utils.js
Outdated
const nbUid = uuidv5(hash, uuidv5.URL) | ||
const content = await zip.generateAsync({ type: 'base64' }) |
There was a problem hiding this comment.
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]
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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 ?
It can be merged! Just have to write ci tests for checking this... Will do it in a new PR 👍 |
Description
Fix #
Additional context
Refactoring some of the code
What is the purpose of this pull request?