Skip to content

Commit

Permalink
Merge branch 'master' into pull_2815
Browse files Browse the repository at this point in the history
  • Loading branch information
psybers authored Aug 26, 2024
2 parents f604be3 + d9adb75 commit 5a23971
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
45 changes: 25 additions & 20 deletions packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,6 +85,7 @@ async function downloadGoCardlessTransactions(
acctId,
bankId,
since,
includeBalance = true,
) {
const userToken = await asyncStorage.getItem('user-token');
if (!userToken) return;
Expand All @@ -106,6 +100,7 @@ async function downloadGoCardlessTransactions(
requisitionId: bankId,
accountId: acctId,
startDate: since,
includeBalance,
},
{
'X-ACTUAL-TOKEN': userToken,
Expand All @@ -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) {
Expand Down Expand Up @@ -683,14 +686,15 @@ export async function syncAccount(
acctId,
bankId,
startDate,
false,
);
} else {
throw new Error(
`Unrecognized bank-sync provider: ${acctRow.account_sync_source}`,
);
}

const { transactions: originalTransactions, accountBalance } = download;
const { transactions: originalTransactions } = download;

if (originalTransactions.length === 0) {
return { added: [], updated: [] };
Expand All @@ -708,7 +712,7 @@ export async function syncAccount(
true,
useStrictIdChecking,
);
await updateAccountBalance(id, accountBalance);

return result;
});
} else {
Expand All @@ -726,6 +730,7 @@ export async function syncAccount(
acctId,
bankId,
startingDay,
true,
);
}

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3279.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [matt-fidd]
---

Optimise GoCardless sync to reduce API usage by removing balance information when unneeded

0 comments on commit 5a23971

Please sign in to comment.