-
Notifications
You must be signed in to change notification settings - Fork 641
Open
Description
I'm building a local-first chat app where data syncs one-way from the cloud to the client (data is only pulled from the cloud, not pushed back). The app has multiple related tables, and I'm concerned about how to manage syncing these tables without causing partial updates or redundant syncs.
Currently, I am syncing all tables every time something changes in the cloud (such as chat message updates). Is this an optimal approach, or should I consider a better solution?
I'm using a custom useEffect hook to handle the sync process, and I invoke this hook multiple times for each function that needs syncing. Here's the current implementation:
useEffect(() => {
if (remoteData === undefined || isSyncingRef.current) return;
const performSync = async () => {
isSyncingRef.current = true;
setSyncState({ isLoading: true, error: null });
try {
await syncData(); // Sync function that pulls all data , (synchronize function by watermelonDB)
setSyncState({ isLoading: false, error: null });
} catch (error) {
setSyncState({
isLoading: false,
error:
error instanceof Error ? error.message : "Sync failed",
});
} finally {
isSyncingRef.current = false;
}
};
performSync();
}, [remoteData]);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels