Make LocalAddressBook's group-membership helpers suspend - #2847
Conversation
…alAddressBook methods suspendable
getContactIdsByGroupMembership to AndroidAddressBook; make Loc…LocalAddressBook's group-membership helpers suspend; move getContactIdsByGroupMembership to synctools
LocalAddressBook's group-membership helpers suspend; move getContactIdsByGroupMembership to synctoolsLocalAddressBook's group-membership helpers suspend
There was a problem hiding this comment.
Pull request overview
This PR continues the effort to make the core local-storage layer (at.bitfire.davdroid.resource.local) a properly suspending, non-blocking API by moving contacts-provider queries into Dispatchers.IO and centralizing provider-access helpers in synctools.
Changes:
- Added a new
AndroidAddressBook.getContactIdsByGroupMembership()helper insynctools, wrappingRemoteExceptionasLocalStorageException. - Converted
LocalAddressBookgroup-membership lookup helpers (and related lookups) tosuspendfunctions and dispatched their provider access ontoDispatchers.IO. - Fixed
LocalJtx*methods that weresuspendbut still performed provider access withoutDispatchers.IO, and documentedfindByName()’s exception behavior at the interface level.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| synctools/src/main/kotlin/at/bitfire/synctools/storage/contacts/AndroidAddressBook.kt | Adds a reusable group-membership query helper and wraps provider RemoteException into LocalStorageException. |
| core/src/main/kotlin/at/bitfire/davdroid/resource/local/LocalAddressBook.kt | Makes group-membership helper calls suspend + IO-dispatched; switches to the new synctools helper. |
| core/src/main/kotlin/at/bitfire/davdroid/resource/local/LocalJtxObject.kt | Ensures JTX update writes run on Dispatchers.IO. |
| core/src/main/kotlin/at/bitfire/davdroid/resource/local/LocalJtxCollection.kt | Ensures JTX find-by-name provider access runs on Dispatchers.IO. |
| core/src/main/kotlin/at/bitfire/davdroid/resource/local/LocalCollection.kt | Documents LocalStorageException behavior for findByName(). |
Suppressed comments (1)
core/src/main/kotlin/at/bitfire/davdroid/resource/local/LocalAddressBook.kt:323
- todo:
findGroupById()can now throwLocalStorageException, but the@Throwsannotation only listsFileNotFoundException.
ab.getGroupOrNull() wraps provider failures as LocalStorageException, which will propagate through this API. If you intend to keep @Throws for Java callers, include LocalStorageException here as well.
@Throws(FileNotFoundException::class)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| withContext(Dispatchers.IO) { | ||
| batch.commit() | ||
| } |
| @@ -311,36 +309,34 @@ open class LocalAddressBook @AssistedInject constructor( | |||
| ab.queryGroupRows(null, where, whereArgs).map { LocalGroup(AndroidGroup(ab, it)) } | |||
|
|
|||
| @Throws(FileNotFoundException::class) | |||
Another step of #2828 (taking #2784 into account).
Purpose
Continues making
at.bitfire.davdroid.resource.local(theLocal*classes betweenSyncManagerand the content providers) a proper suspending API.Short description
LocalAddressBook's group-membership lookup helpers (used byapplyPendingMemberships()) suspend, each dispatching its content-provider call ontoDispatchers.IO.coreinto a newsynctoolsmethod, wrappingRemoteExceptionasLocalStorageExceptionlike its siblings.Local*methods that were already suspend but never actually dispatched their content-provider access ontoDispatchers.IO.findByName()'s exception behavior.Checklist