Open triallax opened 10 months ago
I don't think we need an additional config option for this (in the beginning). The update rate should probably be equal to the update rate of the source (ECB exchange rates), which is once per day, IIRC.
On the note of ECB data: is there a reason this request is proxied through a PHP server rather than queried directly? I came across this while looking into what it would take to make Numbat into a PWA with full offline support. The proxying doesn’t really change that at all, but it does make the deployment of Numbat less self-contained. Is this just for caching purposes in order to be nicer to the ECB service?
On the note of ECB data: is there a reason this request is proxied through a PHP server rather than queried directly?
Yes. I was running into CORS issues when attempting to let the client access the ECB server directly. I'm not an expert on this topic, so please let me know if you think there is a better solution. I'd love to get rid of the proxy step.
caching purposes in order to be nicer to the ECB service?
That's another potential reason, but not the main one. And with the current number of Numbat users, I think we're good :-)
Ah, unfortunately I’m not sure of any ways around that. I thought maybe service workers could offer an escape hatch (since they proxy all requests under the page scope), but they’re bound by the same cross-origin rules and only get access to opaque responses.
Relevant IRC discussion: https://github.com/sharkdp/numbat/issues/139#issuecomment-1795026339
After Numbat fetches currency exchange rates, they are stored for the duration of the session without ever being refreshed. This is problematic for long-running sessions because exchange rates fluctuate over time, and so in a Numbat session running over e.g. a week, the rates will become outdated.
One solution is to fetch them regularly, say once a day (maybe make the frequency configurable?). We could also make it configurable whether to prefetch them at that frequency or to only fetch them after they're outdated and a currency unit was used. This solution raises the question of how to handle network errors when refetching the exchange rates; we should probably let the user know about the failure lest they use outdated exchange rate information.
Thoughts?