Skip to content

Conversation

@mbrandonw
Copy link
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
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
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
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).

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
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.

3 participants