backend: fix off-by-one error in accounts scan #3512
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hidden accounts are added and scanned so they can be shown if they are not empty. This should have happened for the first 5 accounts always (since we allowed 5 empty accounts to be added), but further accounts only if the previous account was non-empty.
maybeAddHiddenUnusedAccounts()
had an off-by-one error where we added and scanned the sixth account even if all accounts before were empty. It should have stopped at the fifth.As a result, adding a new account worked even if the user already had 5 accounts, even if the last account was empty, as adding an account implicitly assumes that existing hidden accounts only could exist if they could be added.
We can fix the off-by-one, but since there might be users out there (even if unlikely) that added such a sixth account, we now should always auto-discover the first six instead of the first five accounts, even if all are empty, so we bump this number. This should not put more load on our servers, as the app already always scanned six accounts due to this bug.
Before asking for reviews, here is a check list of the most common things you might need to consider: