Skip to content

Use metadatabase to query sync metadata.#270

Merged
mbrandonw merged 5 commits into
mainfrom
fix-share-query
Oct 24, 2025
Merged

Use metadatabase to query sync metadata.#270
mbrandonw merged 5 commits into
mainfrom
fix-share-query

Conversation

@mbrandonw
Copy link
Copy Markdown
Member

All reads/writes to the metadatabase should happen through the dedicated metadatabase connection because the user's connection may not have the metadatabase attached. This can be tricky to get right, and we seem to have a spot where we forgot to use the metadatabase directly.

  • Add a test that deletes shares when the metadatabase is not attached.

@@ -0,0 +1,69 @@
#if canImport(CloudKit)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a new test suite to specifically test joining to the metadatabase when it is attached.

}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func deleteShare() async throws {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test was failing prior to the change made in this PR.

$0.dataManager = InMemoryDataManager()
}
},
.attachMetadatabase(false)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's not attach the metadatabase in tests by default, and instead opt into it explicitly.

struct ModifyRecordsCallback {
fileprivate let operation: @Sendable () async -> Void
func notify() async {
struct ModifyRecordsCallback<ReturnValue> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently when we invoke notify() in tests it doesn't return the results from the modify… call. So I updated this bit of library code to allow for that in future tests that may want to assert on that information directly.

@mbrandonw mbrandonw merged commit 5cf865c into main Oct 24, 2025
5 checks passed
@mbrandonw mbrandonw deleted the fix-share-query branch October 24, 2025 17:19
bok- pushed a commit to bok-/sqlite-data-with-traits that referenced this pull request Dec 15, 2025
* Use metadatabase to query sync metadata.

* Added a test

* dont attach metadatabase for base suite.

* add test for attached metadatabase
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