diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts index cf2e25197dc..891763a0aac 100644 --- a/packages/loot-core/src/server/accounts/sync.ts +++ b/packages/loot-core/src/server/accounts/sync.ts @@ -54,13 +54,6 @@ function getAccountBalance(account) { } } -async function updateAccountBalance(id, balance) { - await db.runQuery('UPDATE accounts SET balance_current = ? WHERE id = ?', [ - amountToInteger(balance), - id, - ]); -} - export async function getGoCardlessAccounts(userId, userKey, id) { const userToken = await asyncStorage.getItem('user-token'); if (!userToken) return; @@ -92,6 +85,7 @@ async function downloadGoCardlessTransactions( acctId, bankId, since, + includeBalance = true, ) { const userToken = await asyncStorage.getItem('user-token'); if (!userToken) return; @@ -106,6 +100,7 @@ async function downloadGoCardlessTransactions( requisitionId: bankId, accountId: acctId, startDate: since, + includeBalance, }, { 'X-ACTUAL-TOKEN': userToken, @@ -116,19 +111,27 @@ async function downloadGoCardlessTransactions( throw BankSyncError(res.error_type, res.error_code); } - const { - transactions: { all }, - balances, - startingBalance, - } = res; + if (includeBalance) { + const { + transactions: { all }, + balances, + startingBalance, + } = res; - console.log('Response:', res); + console.log('Response:', res); - return { - transactions: all, - accountBalance: balances, - startingBalance, - }; + return { + transactions: all, + accountBalance: balances, + startingBalance, + }; + } else { + console.log('Response:', res); + + return { + transactions: res.transactions.all, + }; + } } async function downloadSimpleFinTransactions(acctId, since) { @@ -683,6 +686,7 @@ export async function syncAccount( acctId, bankId, startDate, + false, ); } else { throw new Error( @@ -690,7 +694,7 @@ export async function syncAccount( ); } - const { transactions: originalTransactions, accountBalance } = download; + const { transactions: originalTransactions } = download; if (originalTransactions.length === 0) { return { added: [], updated: [] }; @@ -708,7 +712,7 @@ export async function syncAccount( true, useStrictIdChecking, ); - await updateAccountBalance(id, accountBalance); + return result; }); } else { @@ -726,6 +730,7 @@ export async function syncAccount( acctId, bankId, startingDay, + true, ); } diff --git a/upcoming-release-notes/3279.md b/upcoming-release-notes/3279.md new file mode 100644 index 00000000000..c72004b85c1 --- /dev/null +++ b/upcoming-release-notes/3279.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [matt-fidd] +--- + +Optimise GoCardless sync to reduce API usage by removing balance information when unneeded