【问题标题】:synchronization with pouchdb and couchdb与 pouchdb 和 couchdb 同步
【发布时间】:2017-09-15 15:01:58
【问题描述】:

我想为数据库同步的时​​间做一个进度条。计算要同步的文档数的请求太长。我尝试在 couchdb 数据库上使用请求 GET _active_tasks 但它返回一个空的 json。我尝试使用 Pouchdb 函数复制的更改事件,但未显示 info 变量。你有其他的进度条技术吗,或者你知道我曾经尝试过的技术是如何使用的吗?

【问题讨论】:

    标签: javascript couchdb pouchdb nosql


    【解决方案1】:

    我还没有找到完美的解决方案,但对我们来说似乎“足够好”的解决方案已经

    1. 获取有关源数据库的信息,以了解“最终目标”是什么。

    2. 添加一个“更改”回调(就像您在回答中提到的那样),您会在其中收到一个带有已复制的 last_seq 的信息对象。将其除以您从源中获得的 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);
          });
       })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      • 2016-11-26
      • 2020-08-02
      相关资源
      最近更新 更多