为什么 couchbase lite 总是同步

Why couchbase lite is always syncronizing

我在 Android 上使用 couchbase lite 1.4。我注意到我的 Database 对象总是同步数据,即使我的服务器数据库没有变化。 这是我的代码:

master.addChangeListener(new Database.ChangeListener() {
                @Override
                public void changed(Database.ChangeEvent event) {

                    if (event.isExternal()) {
                        for (DocumentChange dc : event.getChanges()) {
                            if (dc.isDeletion()) {
                                Document doc = event.getSource().getDocument(dc.getDocumentId());
                                try {
                                    doc.purge();
                                } catch (CouchbaseLiteException e) {
                                    Log.i("Synchronization","error"+e.getMessage());
                                }
                            }
                            Log.i("Synchronization",
                                    "total documents"+master.getDocumentCount());
                            Log.i("Synchronization",
                                    "id=>"+dc.getDocumentId()+ " revision=>"+ 
                                            dc.getRevisionId()+ " is deletion ?"+dc.isDeletion() +
                                            "is conflict ?"+dc.isConflict());
                            Log.i("Synchronization",
                                    "total documents are"+master.getDocumentCount());
                        }
                    }
                }
            });

            ViewHolder.initAllViews(master, work);

这就是我在 logcat 上看到的:

05-31 19:30:57.544 I/Synchronization: id=>71ad7c09474bb379973a586d41faa376 revision=>3-ff6f2413c947e6679bba9c5d9a8ed056 es borrado?true esta en conflicto?false
05-31 19:31:07.759 I/Synchronization: total documentos 1165510
05-31 19:31:17.951 I/Synchronization: total documentos 1165510
05-31 19:31:17.951 I/Synchronization: id=>c034b94e3b0d2331b90e5ec801bcb83f revision=>11-174ab092fae645e611832a1532d53d7c es borrado?true esta en conflicto?false
05-31 19:31:28.107 I/Synchronization: total documentos1165510
05-31 19:31:38.268 I/Synchronization: total documentos1165510
05-31 19:31:38.269 I/Synchronization: id=>d0bbb7231659b48fa893e34cc4c2b90e revision=>12-a990bdc7881d8cc45fd1585afbeb91e2 es borrado?true esta en conflicto?false
05-31 19:31:48.437 I/Synchronization: total documentos1165510
05-31 19:31:58.710 I/Synchronization: total documentos1165510
05-31 19:31:58.710 I/Synchronization: id=>dbebc1b9c32f33a90a124560cf8b0a3a revision=>11-295d06f0148c4cbbe96920a517786ada es borrado?true esta en conflicto?false
05-31 19:32:08.902 I/Synchronization: total documentos 1165510
05-31 19:32:19.135 I/Synchronization: total documentos 1165510
05-31 19:32:19.135 I/Synchronization: id=>434c1966903c13895699240e1198d8e8 revision=>9-0ca58c84c7ddf09edd1e15f22c3bdafb es borrado?true esta en conflicto?false
05-31 19:32:29.315 I/Synchronization: total documentos 1165510:

如您所见,我收到的文档总数始终相同

1165510

所以文档永远不会被清除,但数据库总是同步数据,这是我的问题。 另一方面,在数据库服务器站点上,如果我尝试通过 Id 查找文档(我从日志 cat 复制的一个文档,例如最后一个:434c1966903c13895699240e1198d8e8),我从服务器得到这个答案:

关于我做错了什么的任何线索?

新添加:当我在服务器站点中删除文档时,我遇到了问题

"_deleted":true

这里有几件事:

  • 清除已删除的文档不会更改文档计数。那些 文档 正在被清除。
  • 此外,在本地清除的文档将在本地由 以本地数据库为目标的复制(从中提取或推送到)。

引用在评论中发布正确答案的@Jay:

Deleting a document (at the server) won't stop a document from replicating to other databases.

相反,使用清除(在服务器上)将完全删除文档,防止其复制到其他数据库。 (当然注意,不会导致文档在其他数据库中被删除。)