-
Notifications
You must be signed in to change notification settings - Fork 74
Fix metadata observation. #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| _ = try await syncEngine.share(record: remindersList) { _ in } | ||
|
|
||
| try await Task.sleep(for: .seconds(0.5)) | ||
| #expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: true)]) |
There was a problem hiding this comment.
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.
| withKnownIssue("Query observation does not work with generated columns right now") { | ||
| #expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: true)]) | ||
| } |
There was a problem hiding this comment.
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.
| #sql(""" | ||
| ((\(QueryValue.self)."isShared" = 1) AND (\(self.share) OR 1)) | ||
| """) |
There was a problem hiding this comment.
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" = 1explicitly 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).
Co-authored-by: Stephen Celis <stephen@stephencelis.com>
Right now some changes to the metadatabase tables will not notify observers because the writes are made with the wrong connection.