【问题标题】:Timestamp based sync, how to reduce the mobile data usage基于时间戳的同步,如何减少移动数据的使用
【发布时间】:2012-11-05 21:57:04
【问题描述】:

这就是我现在执行同步的方式:

 * 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
 * 

问题是,下次同步时,上次同步的项目会出现在“什么都不做”部分,但我的应用是移动应用,所以数据浪费很大。

我想过把物品的更新时间设置为TIMESTAMP,但我认为有两个客户端同时同步的情况,有可能不同步,因为物品的实际上传时间不是里面的更新时间字段,如果有一个客户端在两次时间之间检查了服务器,则此项目丢失。

我正在使用 Google Tasks API,我无法更改服务器端的实现。

有什么建议吗?

【问题讨论】:

    标签: android timestamp sync


    【解决方案1】:

    使用时间戳执行此操作可能会由于时区而导致一些问题。也许为服务器端的更新定义一个 id 并将您的应用当前最大数据版本 id 与服务器的比较可能更可靠和高效

    【讨论】:

    • 我忘了说我正在使用 Google Task API,我无法更改服务器端...关于时区,它始终是 unix 时间。
    • 这改变了一切。我会尽快相应地改变我的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 2015-08-29
    • 2018-11-05
    • 2018-05-27
    • 1970-01-01
    • 2020-11-23
    相关资源
    最近更新 更多