如何增量地更新本地parse.com数据库?

时间:2022-09-15 15:49:35

i have a parse.com based app with offline capabilities where the whole database is stored locally (localStorage on web clients and parse.com local database on mobile clients). I am looking for a design solution to efficiently update the local database with latest changes in the remote database. The options that I could think of are:

我有一个基于parse.com的应用程序,它具有离线功能,可以将整个数据库存储在本地(web客户端上的localStorage和移动客户端上的parse.com本地数据库)。我正在寻找一个设计方案,以有效地更新本地数据库,并在远程数据库中进行最新的更改。我能想到的选项是:

  1. Journaling with code triggers. Setup cloud code triggers (afterSave, afterDelete) for every object and add a log to the journal table every time an object has been saved or destroyed. The clients will query the table for updates and remember lastUpdateTime for subsequent requests.

    日志记录代码触发器。为每个对象设置云代码触发器(afterSave, afterDelete),并在每次保存或销毁对象时向日志表添加日志。客户端将查询该表进行更新,并为后续请求记住lastUpdateTime。

    Pros: a) we can have a very detailed summary what has been changed and who made the change. b) all the changes are instantly available for other clients (e.g. table call be polled for notifications in real time with little delays)

    优点:a)我们可以有一个非常详细的总结什么被改变了,谁做了改变。b)所有更改对其他客户端都是即时可用的(例如,表调用要实时轮询通知,且不会延迟)

    Cons: a) there may be too many entries in the table

    缺点:a)表格中可能有太多的条目。

  2. Journaling with background job. Setup a background job that queries all tables by updatedAt, populates journal table and saves the lastUpdateTime for subsequent requests.

    对背景的工作日志。设置一个后台作业,该作业通过updatedAt查询所有表,填充日志表,并为后续请求保存lastUpdateTime。

    Pros: a) less entries in the journal table

    优点:a)较少的条目在日志表。

    Cons: a) changes are available with unpredictable delay (not suitable for real time notifications?) b) cannot track deletes, there's still a need to setup another table to track deletes or implement soft-delete c) less details in the log (e.g. when object is created by one user and deleted by another user, we will not know who created an object)

    缺点:a)变化是可用的和不可预测的延迟(不适合实时通知?)b)不能删除,还有一个需要设置另一个表来跟踪删除或实现软删除日志中c)更少的细节(例如,当用户和删除对象是由一个由另一个用户,我们不会知道是谁创建了一个对象)

  3. No journal. All clients query all tables by updatedAt and store lastUpdateTime for subsequent requests.

    没有日志。所有客户机都通过updatedAt查询所有表,并为后续请求存储lastUpdateTime。

    Pros: a) easy to implement, b) changes are instantly available

    优点:a)容易实现,b)变化是即时可用的

    Cons: a) same problem with deletes as in 2, b) inefficient (i believe that querying 20+ tables by all clients is not a good idea

    缺点:a)删除的问题与2中相同,b)效率低下(我认为所有客户端查询20+表不是一个好主意

We also have an UI where user can look through the recent activity (who changed what), so I kind of lean towards number 1 approach, but the potential size of the table is worrying me.

我们也有一个用户界面,用户可以查看最近的活动(谁更改了什么),所以我有点倾向于第一种方法,但是表的潜在大小让我担心。

1 个解决方案

#1


1  

Client needs ability to recover irrespective of current state. This is critical if you are using local storage that may get cleared by the user. In that case you need a recoverable state. Additionally the client needs to be able to fetch only the transaction required / relevant to it.

客户需要恢复能力,无论当前状态如何。如果您使用的是可能被用户清除的本地存储,这是非常重要的。在这种情况下,您需要一个可恢复的状态。此外,客户端需要能够只获取所需的/与之相关的事务。

  1. Implementing a transaction store on the backend
  2. 在后端实现事务存储
  3. Creating a recovery mechanism in case the localstorage offline is corrupted
  4. 在本地存储脱机损坏的情况下创建恢复机制
  5. Journaling with code triggers or use of event source db type mechanism so that you have complete history and can use that to build tables for the client.
  6. 带有代码触发器的日志记录或使用事件源db类型机制,这样您就有了完整的历史,并且可以使用它为客户端构建表。

In conclusion - Modified Journaling with Code Triggers (Modified to recover and storing the state for client in server and using that to query the data)

最后,通过代码触发器修改日志记录(修改后恢复并存储服务器上的客户机状态,并使用它查询数据)

#1


1  

Client needs ability to recover irrespective of current state. This is critical if you are using local storage that may get cleared by the user. In that case you need a recoverable state. Additionally the client needs to be able to fetch only the transaction required / relevant to it.

客户需要恢复能力,无论当前状态如何。如果您使用的是可能被用户清除的本地存储,这是非常重要的。在这种情况下,您需要一个可恢复的状态。此外,客户端需要能够只获取所需的/与之相关的事务。

  1. Implementing a transaction store on the backend
  2. 在后端实现事务存储
  3. Creating a recovery mechanism in case the localstorage offline is corrupted
  4. 在本地存储脱机损坏的情况下创建恢复机制
  5. Journaling with code triggers or use of event source db type mechanism so that you have complete history and can use that to build tables for the client.
  6. 带有代码触发器的日志记录或使用事件源db类型机制,这样您就有了完整的历史,并且可以使用它为客户端构建表。

In conclusion - Modified Journaling with Code Triggers (Modified to recover and storing the state for client in server and using that to query the data)

最后,通过代码触发器修改日志记录(修改后恢复并存储服务器上的客户机状态,并使用它查询数据)