PouchDB / CouchDB序列计数器重复 [英] PouchDB/CouchDB Sequence Counter on Replicate

查看:81
本文介绍了PouchDB / CouchDB序列计数器重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实时将刚铸造的pouchdb(3.3.1)同步到已建立的(iris)沙发上。



最初的复制发生了成功(触发了 pause 事件。)



如果我在 info()上执行了在本地,我得到的 362 的update_seq。如果我在遥控器上执行 info(),它将显示 4201 的update_seq。



<我认为这对我来说很有意义:本地数据库没有修订-仅叶子(即数据库中有362个叶子),而远程数据库序列计数器反映了自首次创建以来所做的所有历史更改。



我的问题是:如何以编程方式确定两个数据库之间序列计数器的初始偏移是什么?我特别希望能够衡量初始复制的进度。

解决方案

您无法真正比​​较两个数据库中的序列。但是,您可以在远程数据库上执行 db.info(),获取 update_seq ,然后进行比较复制期间在 on('change')事件中提供给您的 last_seq



如果您想看到这样的示例,请使用 NPM浏览器正是这样做的,以将百分比计数器显示在顶部。 (它也使用pouchdb-load,但是原理是一样的,因为seqs也报告在这里。)该代码是开源的,因此请随时检查其工作原理。 :)



编辑:,如注释中所指出,如果您使用的是 sync 而不是复制,而是在读取 last_seq direction 参数。 c $ c>。同样对于Cloudant,您将需要在-上拆分字符串以获取整数seq。


I am live syncing a freshly minted pouchdb (3.3.1) to an established (iris) couchdb.

The initial replication happens successfully (pause event fired).

If I do info() on the Local, I get an update_seq of 362. If I do info() on the remote, it shows an update_seq of 4201.

I think this makes sense to me: the local db has no revisions - only the leaves (i.e. there are 362 leaves in the db) whereas the remote db sequence counter reflects all the historical changes that have been made since it was first created.

My question is: how can I programatically determine what the initial 'offset' in sequence counter is between the two databases? In particular I want to be able to measure the progress of the initial replication.

解决方案

You can't really compare the seqs across two databases. However, you can do a db.info() on the remote database, grab the update_seq, and then compare that to the last_seq that is given to you in the on('change') event during replication. This will tell you how much progress you've made.

If you would like to see an example of this, the NPM Browser does exactly this, to show the percent counter at the top. (It uses pouchdb-load as well, but the principle is the same, since the seqs are reported there as well.) The code is open-source, so feel free to check out how it works. :)

Edit: as pointed out in a comment, if you are using sync rather than replicate, you need to check the direction parameter when reading last_seq. Also for Cloudant, you will need to split the string on - to get the integer seq.

这篇关于PouchDB / CouchDB序列计数器重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆