Timestamp based sync, how to reduce the mobile data usage

会有一股神秘感。 提交于 2019-12-10 00:12:48

问题


This is how I perform a sync now:

 * get preference "timestamp" and save to variable TIMESTAMP
 * save current time to preference "timestamp"      (2)
 * query server side items with update time bigger than TIMESTAMP
 * for each item
 *      compare with local item's per item update_time
 *      if server side is newer
 *          update local
 *      else if local is newer
 *          set item update time to now             (1)
 *          upload
 *          save back
 *      else if equal
 *          do nothing
 * 

The question is, when I sync next time, the last time synced items will appear in the "do nothing" section, but my app is a mobile app, so there is a large data waste.

I thought about set the items's update time to TIMESTAMP, but I think there are situations that two client is syncing the same time, and there are chance of out sync, because the item's real uploaded time is not what in it's update time field, and if one client checked the server between the two time, this item is missed.

I'm using Google Tasks API, I cannot change the implement of the server side.

Any suggestions?


回答1:


Doing this with timestamp may be cause some problems due to timezones.Perhaps defining an id for updates of server side and comparing your apps current max data version id with server's can be more reliable and efficient



来源:https://stackoverflow.com/questions/13429062/timestamp-based-sync-how-to-reduce-the-mobile-data-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!