Skip to content

feat: add serverless support, fix: better cache handling#93

Open
DuckySoLucky wants to merge 7 commits intomasterfrom
fix/serverless-support-and-corrupted-file-fix
Open

feat: add serverless support, fix: better cache handling#93
DuckySoLucky wants to merge 7 commits intomasterfrom
fix/serverless-support-and-corrupted-file-fix

Conversation

@DuckySoLucky
Copy link
Collaborator

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.js module 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.

Copy link
Collaborator

@MattTheCuber MattTheCuber left a comment

Choose a reason for hiding this comment

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

So, in server less you can't write to files or what?

@MattTheCuber
Copy link
Collaborator

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
@MattTheCuber
Copy link
Collaborator

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.

@DuckySoLucky
Copy link
Collaborator Author

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

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.

4 participants