Turbo Login is an advanced optimization for the initial (login) sync that can be up to 5.3x faster and more memory-efficient. It is intended for very large datasets.
Constraints & Requirements:
- Use Case: Only for the first sync when the database is empty. Using it on an existing database is a serious error.
- Data Format:
pullChanges must return the raw JSON text via the syncJson key, rather than a parsed object. - Environment: Only works with
SQLiteAdapter with JSI enabled. It does NOT work on the web or when Chrome Remote Debugging is enabled. - API Status: Marked as
unsafe (the API may change).
Implementation Pattern:
Set unsafeTurbo: true in the synchronize options. In pullChanges, if useTurbo is true, return { syncJson: rawJsonText } instead of the standard { changes, timestamp } object.
Handling Extra Data:
Since you cannot process JSON in pullChanges during a Turbo sync, use the onDidPullChanges callback to process additional metadata or messages sent from the server.
const isFirstSync = ...
const useTurbo = isFirstSync
await synchronize({
database,
pullChanges: async ({ lastPulledAt, schemaVersion, migration }) => {
const response = await fetch(`https://my.backend/sync?${...}`)
if (!response.ok) {
throw new Error(await response.text())
}
if (useTurbo) {
// NOTE: DO NOT parse JSON, we want raw text
const json = await response.text()
return { syncJson: json }
} else {
const { changes, timestamp } = await response.json()
return { changes, timestamp }
}
},
unsafeTurbo: useTurbo,
onDidPullChanges: async ({ messages }) => {
if (messages) {
messages.forEach((message) => {
alert(message)
})
}
},
})