Skip to content

Fix metadata observation.#369

Merged
mbrandonw merged 11 commits into
mainfrom
metadatabase-writer
Jan 13, 2026
Merged

Fix metadata observation.#369
mbrandonw merged 11 commits into
mainfrom
metadatabase-writer

Conversation

@mbrandonw
Copy link
Copy Markdown
Member

Right now some changes to the metadatabase tables will not notify observers because the writes are made with the wrong connection.

_ = try await syncEngine.share(record: remindersList) { _ in }

try await Task.sleep(for: .seconds(0.5))
#expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: true)])
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 fails without these changes.

Comment on lines +680 to +682
withKnownIssue("Query observation does not work with generated columns right now") {
#expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: true)])
}
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.

Observation of generated columns does not currently work.

Comment on lines +136 to +138
#sql("""
((\(QueryValue.self)."isShared" = 1) AND (\(self.share) OR 1))
""")
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.

We're employing two tricks here:

  • First we are working around that generated columns are not observed by mixing in ("share" OR 1) into the query. That "touches" the "share" column for observation, but SQLite is able to effectively eliminate this term from the query and does not change what indexes it will use.
  • Further, by checking "isShared" = 1 explicitly we can help SQLite choose the index on "isShared`.

Note that we do want to still keep the generated column because it is what gives us an efficient index (better to index an integer column than a blob column).

Comment thread Sources/SQLiteData/CloudKit/SyncMetadata.swift Outdated
mbrandonw and others added 3 commits January 12, 2026 15:06
@mbrandonw mbrandonw merged commit b373f0c into main Jan 13, 2026
5 checks passed
@mbrandonw mbrandonw deleted the metadatabase-writer branch January 13, 2026 13:55
doozMen pushed a commit to doozMen/sqlite-data that referenced this pull request Jan 22, 2026
* Fix metadata observation.

* Workaround for generated column observation behavior.

* optimization

* clean up

* clean up

* fix

* fix

* update hasLastKnownServerRecord"

* Update Sources/SQLiteData/CloudKit/SyncMetadata.swift

Co-authored-by: Stephen Celis <stephen@stephencelis.com>

* format

* consistent order

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
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