Skip to content

Make LocalAddressBook's group-membership helpers suspend - #2847

Closed
rfc2822 wants to merge 2 commits into
mainfrom
localcollection-suspend-6
Closed

Make LocalAddressBook's group-membership helpers suspend#2847
rfc2822 wants to merge 2 commits into
mainfrom
localcollection-suspend-6

Conversation

@rfc2822

@rfc2822 rfc2822 commented Aug 20, 2026

Copy link
Copy Markdown
Member

Another step of #2828 (taking #2784 into account).

Purpose

Continues making at.bitfire.davdroid.resource.local (the Local* classes between SyncManager and the content providers) a proper suspending API.

Short description

  • Made LocalAddressBook's group-membership lookup helpers (used by applyPendingMemberships()) suspend, each dispatching its content-provider call onto Dispatchers.IO.
  • Moved the raw group-membership query out of core into a new synctools method, wrapping RemoteException as LocalStorageException like its siblings.
  • Fixed two other Local* methods that were already suspend but never actually dispatched their content-provider access onto Dispatchers.IO.
  • Documented findByName()'s exception behavior.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@rfc2822 rfc2822 changed the title Move getContactIdsByGroupMembership to AndroidAddressBook; make Loc… Make LocalAddressBook's group-membership helpers suspend; move getContactIdsByGroupMembership to synctools Aug 20, 2026
@rfc2822 rfc2822 changed the title Make LocalAddressBook's group-membership helpers suspend; move getContactIdsByGroupMembership to synctools Make LocalAddressBook's group-membership helpers suspend Aug 20, 2026
@rfc2822
rfc2822 requested a lite review from Copilot August 20, 2026 17:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in synctools, wrapping RemoteException as LocalStorageException.
  • Converted LocalAddressBook group-membership lookup helpers (and related lookups) to suspend functions and dispatched their provider access onto Dispatchers.IO.
  • Fixed LocalJtx* methods that were suspend but still performed provider access without Dispatchers.IO, and documented findByName()’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 throw LocalStorageException, but the @Throws annotation only lists FileNotFoundException.

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.

Comment on lines +393 to +395
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)
Base automatically changed from localcollection-suspend-5 to main August 21, 2026 08:57
@rfc2822 rfc2822 closed this Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants