简体   繁体   English

与pouchdb和couchdb同步

[英]synchronization with pouchdb and couchdb

I would like to do a progress bar for the time when the database synchronize. 我想在数据库同步的时​​候做一个进度条。 The request which counts the number of documents to synchronize is too long. 计算要同步的文档数的请求太长。 I tried with the request GET _active_tasks on the couchdb database but it returns an empty json. 我在沙发数据库中尝试了GET _active_tasks请求,但它返回了一个空json。 I tried with the change event of the Pouchdb function replicate but the info variable doesn't display. 我尝试了Pouchdb函数复制的change事件,但是没有显示info变量。 Have you others technics for the progress bar or would you know how used the technics I have ever tried ? 您是否还有其他用于进度条的技术,或者您知道我曾经尝试过的技术使用过吗?

I have not found a perfect solution, but one that seemed 'good enough' for us has been 我还没有找到完美的解决方案,但是对我们来说似乎“足够好”的解决方案是

  1. get info about source db, to know what the 'end goal' is. 获取有关源数据库的信息,以了解“最终目标”是什么。

  2. Add a 'changes' callback (like you mentioned in your answer), where you receive an info object with the last_seq that has been replicated. 添加一个“ changes”回调(如您在答案中提到的那样),在其中您将收到一个信息对象,该对象具有已复制的last_seq。 Divide this with the update_seq you got from the source, and update your progress bar. 将其与从源代码获得的update_seq相除,并更新进度条。

~

Q.all(source.info())
   .then(function(sourceInfo) {
      var replication = source.replicate.to(target);
      var startingpoint;
      replication.on('change', function(info) {
         // the first time we get a replication change, 
         // take the last_seq as starting point for the replication
         // and calc fractions based on that
         var fraction = 0;
         if(typeof startingpoint === "undefined") {
            startingpoint = info.last_seq;
         } else {
            fraction = (info.last_seq - startingpoint) / (sourceInfo.update_seq - startingpoint); 
         }
         // Whatever you need to do to update ui here
         updateUi(fraction);
      });
   })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM