-
I have a Posts table where users post blog entries that I am syncing to a MySQL backend. I have syncing working for the first user that logs in (user 1). Their authentication/bearer token is being saved to AsyncStorage. When user 1 logs out and user 2 logs in I am having issues syncing as the last_pulled_at date is already up-to-date. On the server side my sync adapter is only allowing syncing based on the authenticated user. So user 1 gets synced correctly, but nothing from user 2 is synced to WatermelonDB Posts table (this is desired functionality, just issue with syncing the users separately as I don't want to sync the entire back-end database). My idea to get this working is changing the sync function to use a last_pulled_at date that is individual for each user. Example: User 1 logs in for the first time, auth bearer/token gets set in AsyncStorage along with an initial last_pulled_at value of 0. When sync is called, pass that variable from asyncstorage to the sync function. Then get last_pulled_at date from Watermelondb and update the value in AsyncStorage. Then when user logs out and user 2 logs in the same process is followed. Problem with this solution is I am not sure how to pull last_pulled_at date from WatermelonDB. Should I try to pull from WatermelonDB or should I just create new Unix date stamp each time sync function is requested. This is my thought on it but if anyone has any suggestions I would greatly appreciate it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I ended up creating my own lastPulledAt date. Initially set lastPulledAt as 0 for every user. Then updated this value and stored it in react-native-mmkv as an array of objects. [{id: "1", lastPulledAt: "12129323232"}]. Grabbed lastPulledAt from storage, sync by passing this date, then updating lastPulledAt with Date.now(). Then storing back to mmkv storage. Seems to work great. |
Beta Was this translation helpful? Give feedback.
I ended up creating my own lastPulledAt date. Initially set lastPulledAt as 0 for every user. Then updated this value and stored it in react-native-mmkv as an array of objects. [{id: "1", lastPulledAt: "12129323232"}]. Grabbed lastPulledAt from storage, sync by passing this date, then updating lastPulledAt with Date.now(). Then storing back to mmkv storage. Seems to work great.