feat: add serverless support, fix: better cache handling#93
feat: add serverless support, fix: better cache handling#93DuckySoLucky wants to merge 7 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors item fetching logic to support serverless environments and improves error handling for corrupted cache files. The changes extract the items fetching logic into a dedicated helper module and add try-catch error handling to gracefully recover from corrupted cache files by fetching fresh data from the API.
Changes:
- Extracted items fetching logic into a new
helper/items.jsmodule for better code organization and reusability - Added error handling in
loadItems()to detect and recover from corrupted cache files by deleting the corrupt file and fetching fresh data - Refactored
NetworthManager.updateItems()to use the new extracted helper function
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| helper/items.js | New helper module that extracts the items fetching logic with retry mechanism from NetworthManager |
| managers/NetworthManager.js | Simplified updateItems method to delegate to the new getItems helper function |
| constants/itemsMap.js | Added try-catch error handling in loadItems to gracefully handle corrupted cache files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
MattTheCuber
left a comment
There was a problem hiding this comment.
So, in server less you can't write to files or what?
|
Also, does that mean in serverless environments it will request the API every time the library is called or importing or something? Idk much about serverless, just curious. |
1 similar comment
|
Also, does that mean in serverless environments it will request the API every time the library is called or importing or something? Idk much about serverless, just curious. |
Originalyl added to eliminate cold starts, it first attempts to read from cache file. If the file is missing or unreadable, it fetches the data and stores it in RAM. Once cached in memory, the data is used until the next refresh (every X hours iirc?), so no need for any external requests / requests on each calc. So this just stops it from trying to read / write file on serverless |
Description
Fixes https://canary.discord.com/channels/720018827433345138/1461755944198340859
Fixes https://canary.discord.com/channels/720018827433345138/1449648221721726976