JoCuTo
JoCuTo

Reputation: 2483

Why couchbase lite is always syncronizing

I am using couchbase lite 1.4 on Android. I have noted that my Database object is always synchronizing data, even when there is not changes in my server database. This is my code :

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);

and this is what I see on my 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:

as you can see I am always getting the same number of total documents

1165510

so the document are never purged but the database is always syncronizing data , that is my problem. In the other hand on the Database server site if I try to find a document by the Id (one I copy from the log cat for example the last one : 434c1966903c13895699240e1198d8e8 ) I get this answer by the server :

enter image description here

Any clue about what I am doing wrong?

New added: I am facing that the problem comes when I delete documents in the server site doing

"_deleted":true

Upvotes: 0

Views: 78

Answers (1)

G. Blake Meike
G. Blake Meike

Reputation: 6715

There are a couple things here:

  • Purging a deleted document will not change the document count. Those documents are being purged.
  • Also, a document that is purged locally will be restored, locally, by a replication that targets the local db (pull from or push to).

To quote @Jay, who posted a correct answer in a comment:

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

Using Purge (at the server), instead, will remove the document completely, preventing its replication to other databases. (Note, of course, that it will not cause the document to be deleted in the other databases.)

Upvotes: 1

Related Questions