fix: Wrap updateConversationTags transaction in a background task - #2659
Merged
Conversation
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
Comment on lines
+893
to
+896
| if bgTask.isExpired { | ||
| realm.cancelWriteTransaction() | ||
| return | ||
| } |
Collaborator
There was a problem hiding this comment.
As discussed, should probably be moved to outside of transaction
Realm writes were open-coded everywhere: get the default realm, begin, mutate, commit, and sometimes take a background assertion so iOS does not suspend us mid write. About half the write sites were missing that assertion. Add RLMRealm.writeTransaction, which does all of that in one place and releases the assertion with a defer, plus NCDatabaseManager.updateTalkAccount(forAccountId:) for the common "change one field on the account" case. Migrate every write site except NCRoomsManager.updateRooms, which needs to bail out mid transaction and keeps its own background task. Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: Ivan Sein <ivan@nextcloud.com>
SystemKeeper
approved these changes
Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Every realm write should run inside a background assertion, so iOS does not
suspend us while the realm write lock is held. The realm lives in the shared
app group container, so being suspended holding its lock is a kill. That was
open-coded at every call site, and about half the write sites were missing it.
RLMRealm.writeTransactionnow does it in one place, releasing the assertionwith a
defer, andNCDatabaseManager.updateTalkAccount(forAccountId:)coversthe common "change one field on the account" case.
NCRoomsManager.updateRoomsis left as it is: it loops over every room on theaccount, which can be hundreds, each with nested deletes. It is the only write
that could realistically run out of background time and need to bail out mid
transaction, so it keeps its own background task and
cancelWriteTransaction().Everywhere else the block is a few statements,
updateConversationTagsincluded — which is why its per item expiration checks are gone.
🤖 AI (if applicable)