From 5eea9ede3aab2e6d7a3d73773bbaded5e637f193 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Mon, 13 Nov 2023 18:45:35 -0700 Subject: [PATCH] avoid extra API call if not required --- ynab/accounts.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ynab/accounts.go b/ynab/accounts.go index 38f56d7..42e9370 100644 --- a/ynab/accounts.go +++ b/ynab/accounts.go @@ -54,6 +54,10 @@ func (c *Client) SetAccountBalance(accountID string, balance int) error { return fmt.Errorf("failed to get ynab account with id '%s': %v", accountID, err) } + if balance == ynabAccount.Data.Account.Balance { + return nil // The YNAB account already has the balance we're requesting, so there is no need to do anything + } + balanceDelta := balance - ynabAccount.Data.Account.Balance balanceDelta += ynabTransactionAmount // Take into account the existing transaction if balanceDelta == 0 {