Repository navigation
fix(api): keep each provider's bank list in memory for an hour - #307
Merged
Merged
Conversation
bankConnection.listInstitutions reached the provider on every call, and Settings > Bank accounts calls it on every visit to show the connected banks' logos. With Enable Banking that is a large GET /aspsps each time. The server now keeps each provider's list for one hour, keyed by provider id, so switching the default provider never serves the old list. A BankInstitutionsUnavailable failure is not kept and still answers SERVICE_UNAVAILABLE, so the next call retries. Closes suiramdev#304 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Nadir Ali <[email protected]>
Owner
|
Lovely, thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The server now keeps each provider's bank list in memory for one hour, so
bankConnection.listInstitutionsstops reaching the provider on every call. The cache lives inpackages/api/src/lib/institutions-cache.ts(institutionsLoaderWith), which takes the clock as an option so the tests can control it; the router builds one loader and uses it whereloadInstitutionswas. Start with that file and its test.Motivation
Since #299 the list is every bank the provider offers, and each call fetched it again: with Enable Banking a large
GET /aspsps. Settings › Bank accounts calls it on every visit just to show the connected banks' logos, and each user and tab made its own call.Drawbacks
A bank activated or removed at the provider shows in Freenary up to an hour later, or at once after a server restart. The cache is per server process, so with several replicas each keeps its own copy. The docs pages say so.
Prior art
The usual in-memory TTL cache, keyed by provider id, that keeps only successful answers.
Evidence
institutions-cache.test.tscovers the acceptance criteria with a fake provider and a controlled clock:BankInstitutionsUnavailablefailure is not kept, still answersSERVICE_UNAVAILABLE, and the next call retries.With the cache check turned off, tests 1 and 4 fail.
Checks run locally:
bun testinpackages/api(656 pass),check-typesinpackages/api, oxlint and oxfmt on the changed files (the pre-commit hook passed).bun run docs:checkreports the same 49 problems with and without this change. They are all Windows path handling in the checker (docs\meta.json: the entry "index" is neither a page nor a subfolder), so CI will be the real check for it.Notes
packages/api/src/lib/institutions-cache.test.ts.docs/explanation/bank-list.md(the one-hour cache, per provider, failures not kept) anddocs/how-to/choose-powens-banks.md(a console change now shows within the hour, not on reload).🤖 Generated with Claude Code