add-account makes two serialized Fava round-trips (add_account, then get_all_accounts) #53

Open
opened 2026-06-16 21:59:39 +00:00 by padreug · 0 comments
Owner

Found in the high-effort code review of PR #46.

views_api.py:3761 — after add_account already did a read+write round-trip against Fava /api/source, the endpoint calls sync_single_account_from_beancount(payload.name), which calls fava.get_all_accounts() (account_sync.py:312) to fetch the entire account list just to find the single row it just wrote. Both calls are serialized behind FavaClient._write_lock.

The endpoint already holds everything needed to mirror the account into libra's DB (name, currencies, target_file, metadata, derivable account_type/user_id/description). The second full-list Fava fetch is wasted work and adds Fava availability as an extra failure mode for the DB-mirror step.

Suggested fix

Mirror the account into the DB from in-process data after a successful add_account, or have sync_single_account_from_beancount accept the already-known account rather than re-fetching get_all_accounts(). Low priority (not a hot path), but it's redundant I/O on a lock-serialized path.

Found in the high-effort code review of PR #46. `views_api.py:3761` — after `add_account` already did a read+write round-trip against Fava `/api/source`, the endpoint calls `sync_single_account_from_beancount(payload.name)`, which calls `fava.get_all_accounts()` (`account_sync.py:312`) to fetch the **entire** account list just to find the single row it just wrote. Both calls are serialized behind `FavaClient._write_lock`. The endpoint already holds everything needed to mirror the account into libra's DB (name, currencies, target_file, metadata, derivable account_type/user_id/description). The second full-list Fava fetch is wasted work and adds Fava availability as an extra failure mode for the DB-mirror step. ### Suggested fix Mirror the account into the DB from in-process data after a successful `add_account`, or have `sync_single_account_from_beancount` accept the already-known account rather than re-fetching `get_all_accounts()`. Low priority (not a hot path), but it's redundant I/O on a lock-serialized path.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/libra#53
No description provided.