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. |
| const nbUid = uuidv5(hash, uuidv5.URL) | ||
| const content = await zip.generateAsync({ type: 'base64' }) |
There was a problem hiding this comment.
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.
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.
@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.
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.
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
vfdev-5
left a comment
There was a problem hiding this comment.
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?