Skip to content

fix(api): keep each provider's bank list in memory for an hour - #307

Merged
suiramdev merged 1 commit into
suiramdev:devfrom
Xnadir:fix/cache-bank-institutions
Nov 22, 2026
Merged

suiramdev merged 1 commit into
suiramdev:devfrom
Xnadir:fix/cache-bank-institutions

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

The server now keeps each provider's bank list in memory for one hour, so bankConnection.listInstitutions stops reaching the provider on every call. The cache lives in packages/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 where loadInstitutions was. 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.ts covers the acceptance criteria with a fake provider and a controlled clock:

  1. Two calls within the hour reach the provider once.
  2. After one hour the next call reloads the list.
  3. A BankInstitutionsUnavailable failure is not kept, still answers SERVICE_UNAVAILABLE, and the next call retries.
  4. Two providers keep separate lists.

With the cache check turned off, tests 1 and 4 fail.

Checks run locally: bun test in packages/api (656 pass), check-types in packages/api, oxlint and oxfmt on the changed files (the pre-commit hook passed). bun run docs:check reports 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

  • Closes Bank list: listInstitutions calls the provider on every request #304
  • No visual change.
  • Tests added: packages/api/src/lib/institutions-cache.test.ts.
  • Docs updated: docs/explanation/bank-list.md (the one-hour cache, per provider, failures not kept) and docs/how-to/choose-powens-banks.md (a console change now shows within the hour, not on reload).
  • No migration and no breaking change.
  • This change was written with the help of Claude Code (AI). I reviewed it and ran the checks above.

🤖 Generated with Claude Code

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]>
@suiramdev
suiramdev merged commit 56d267a into suiramdev:dev Nov 22, 2026
4 checks passed
@suiramdev

Copy link
Copy Markdown
Owner

Lovely, thank you!

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.

Bank list: listInstitutions calls the provider on every request

2 participants