From 1750cd908179b065b58b1a5b2cc2b2ca7c7a5ba8 Mon Sep 17 00:00:00 2001 From: lelemm Date: Sat, 24 Aug 2024 05:49:36 -0300 Subject: [PATCH 1/2] Filter fix when alternating all <-> any (#3278) --- .../src/components/accounts/Account.jsx | 4 ++-- .../src/components/filters/FiltersStack.tsx | 2 +- .../src/components/modals/EditRule.jsx | 12 ++++++++---- upcoming-release-notes/3278.md | 6 ++++++ 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 upcoming-release-notes/3278.md diff --git a/packages/desktop-client/src/components/accounts/Account.jsx b/packages/desktop-client/src/components/accounts/Account.jsx index 01bcc5abd85..b946bcbabae 100644 --- a/packages/desktop-client/src/components/accounts/Account.jsx +++ b/packages/desktop-client/src/components/accounts/Account.jsx @@ -1113,10 +1113,10 @@ class AccountInternal extends PureComponent { ); }; - onConditionsOpChange = (value, conditions) => { + onConditionsOpChange = value => { this.setState({ filterConditionsOp: value }); this.setState({ filterId: { ...this.state.filterId, status: 'changed' } }); - this.applyFilters([...conditions]); + this.applyFilters([...this.state.filterConditions]); if (this.state.search !== '') { this.onSearch(this.state.search); } diff --git a/packages/desktop-client/src/components/filters/FiltersStack.tsx b/packages/desktop-client/src/components/filters/FiltersStack.tsx index 3af0c68b736..02576c5de1d 100644 --- a/packages/desktop-client/src/components/filters/FiltersStack.tsx +++ b/packages/desktop-client/src/components/filters/FiltersStack.tsx @@ -34,7 +34,7 @@ export function FiltersStack({ onReloadSavedFilter: (savedFilter: SavedFilter, value?: string) => void; filterId: SavedFilter; savedFilters: TransactionFilterEntity[]; - onConditionsOpChange: () => void; + onConditionsOpChange: (value: 'and' | 'or') => void; }) { return ( diff --git a/packages/desktop-client/src/components/modals/EditRule.jsx b/packages/desktop-client/src/components/modals/EditRule.jsx index c36e331dc95..c409c77f51a 100644 --- a/packages/desktop-client/src/components/modals/EditRule.jsx +++ b/packages/desktop-client/src/components/modals/EditRule.jsx @@ -94,7 +94,7 @@ export function FieldSelect({ fields, style, value, onChange }) { bare options={fields} value={value} - onChange={value => onChange('field', value)} + onChange={onChange} buttonStyle={{ color: theme.pageTextPositive }} /> @@ -260,7 +260,11 @@ function ConditionEditor({ return ( - + onChange('field', value)} + /> {valueEditor} @@ -373,7 +377,7 @@ function ActionEditor({ action, editorStyle, onChange, onDelete, onAdd }) { onChange('field', value)} /> @@ -838,7 +842,7 @@ export function EditRule({ defaultRule, onSave: originalOnSave }) { setStage(stage); } - function onChangeConditionsOp(name, value) { + function onChangeConditionsOp(value) { setConditionsOp(value); } diff --git a/upcoming-release-notes/3278.md b/upcoming-release-notes/3278.md new file mode 100644 index 00000000000..49cbfcaf6e3 --- /dev/null +++ b/upcoming-release-notes/3278.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [lelemm] +--- + +Filter fix when alternating all <-> any From d9adb750d422d15c0472e7f53bab504695682823 Mon Sep 17 00:00:00 2001 From: Matt Fiddaman Date: Mon, 26 Aug 2024 11:03:57 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=B9=20optimise=20GoCardless=20bank?= =?UTF-8?q?=20sync=20to=20use=20fewer=20api=20calls=20(#3279)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * optimise * lint * release note * psybers feedback --- .../loot-core/src/server/accounts/sync.ts | 45 ++++++++++--------- upcoming-release-notes/3279.md | 6 +++ 2 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 upcoming-release-notes/3279.md 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