-
Notifications
You must be signed in to change notification settings - Fork 277
Optimize exchange rate asset pair cache handling #5829
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
Conversation
50aed5c to
e869a1a
Compare
src/actions/ExchangeRateActions.ts
Outdated
| cryptoPairs: Array.from(cryptoPairMap.values()), | ||
| fiatPairs: Array.from(fiatPairMap.values()) | ||
| cryptoPairs: Array.from(cryptoPairCache.values()), | ||
| fiatPairs: Array.from(fiatPairCache.values()) |
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.
Bug: Cache clears failed rate pairs, causing missing data
The exchange rate cache now only persists asset pairs that successfully returned rate data, rather than all initially requested pairs. If a rate fetch fails, the asset pair is removed from the cache and won't be tracked or re-requested until its associated wallet is active again, potentially causing missing exchange rates.
swansontec
left a comment
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 seems like this would be better, but as Cursor points out, we do run the risk of losing rates that we fail to fetch. It might make sense to pre-populate these two sets with the existing data, which would turn this into an update rather than a stomp.
e869a1a to
1cb0304
Compare
With the cache, and periodic looping, this isn't really necessary and can actually slow down rate updates
d4be29f to
d35d3b7
Compare
| const key = `${pair.fiatCode}_${pair.targetFiat}` | ||
| fiatPairsMap.set(key, { ...pair, isoDate: undefined }) | ||
| } | ||
| out.fiatPairs = Array.from(fiatPairsMap.values()) |
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.
Bug: Historical Exchange Rate Data Integrity Compromised
The deduplication logic in loadExchangeRateCache uses a key that excludes isoDate, causing pairs with the same pluginId/tokenId/targetFiat but different isoDate values to collide and overwrite each other. Since the persisted cache can contain pairs with historical dates (e.g., isoDate: yesterday), only one per key is kept with isoDate cleared to undefined. This loses historical rate pair information that was previously persisted, preventing the app from accurately restoring its previous state after restart when daily rate updates were involved.
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.
This is a good thing
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneRequirements
If you have made any visual changes to the GUI. Make sure you have:
Note
Deduplicates cached asset pairs on load, fetches rates in parallel, then merges successful results back into the pair caches before updating/persisting the cache.
cryptoPairs/fiatPairsvia keyed maps, drop expired entries, and normalize pairs (unsetisoDate).Promise.allSettled) tov3/rates.cryptoPairCache/fiatPairCachebefore writing to disk.current/yesterdaywith timestamps and expirations as before.Written by Cursor Bugbot for commit d35d3b7. This will update automatically on new commits. Configure here.