-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Currently the "check if there are new changes" uses the previous _creationTime as the cursor. Unfortunately, the previous query could have fetched results before an in-progress mutation commits, which could have started prior to what the latest document's _creationTime shows, meaning the next check will miss the commit.
You can use a monotonically increasing sequence number on inserts to keep the cursor, or have some fancier vector clock.
You may also be able to leverage a version number used by the main app's schemas.
In the prosemirror-sync component, I do this with the "version" field: https://github.com/get-convex/prosemirror-sync/blob/ian/thin-client/src/component/schema.ts#L14-L15
The risk is then that concurrent inserts need to be written serially, which generally will happen automatically in convex thanks to the MVCC / OCC w/ auto-retry. However, it can cause DB write conflicts during contentious writes scenarios.
We're thinking about other patterns where we could support a "give me the latest since the last row I queried" but for now _creationTime can be out of order (up to a theoretical max skew of 4 minutes, though usually not more than ~seconds)