my question is:
when I update a document by sync_gateway restful API, the couchbase lite listener gets more than one changes.
My application scenario is A couchbase lite post a document via sg restful API, then D couchbase lite listen to changes. I use QueryListenerChange with one where condition. when getting changes, D gets the document and print it to the printer.
now when I update a document, the printer always prints more than one times. and the android logcat printed a lot of changes logs.
how can I resolve this?
sample graph
I also use database LiveQuery, when to update one document, because when the android device goes to sleep mode, the sync Thread same killed by the system. so I save a heartbeat document in a local database, when over 5 mins, I can’t get the database liveQuery result , I’ll restart sync. but when I put heartbeat document, the android logcat also gets two changes.
is the database level LiveQuery can’t the combination with QueryLiveQuery?
best regrades
hi @hod.greeley,
thanks for your reply.
not every time, Not often.
I have 5 android devices in a channel, one device use liveQuery listen to document and detect document property flag to print. for example, A B C D E android device. A post a document via sync gateway restful API, the E liveQuery the document, when detecting the document print flag is 0, then print it, when printer successful, E received call back, set the print flag to 1 via sg restful API, it means the document had printed.
I paste the sync gateway logs below.
when a normal logs is:
this logs have 4 revision, normal logs have 2 revision. and it’s secenes Not often. when I inspect all logs, I find 2 revision has conflict, I don’t know if my description is clear. how it’s occur conflict?
The dual update of the document sounds like the result of a conflict. If a device pulls a change from the server that conflicts with what it has locally, it will resolve it by choosing one side or the other, then commit a new revision and push that. So two revisions are created.
Conflicts happen when a document is changed in different ways by two clients (or a client and the server) before they’ve had time to replicate the first change.
thanks for your reply. as your mention that issue is my code issue.If have many device share a one channel and sg user, documents are prone to conflicts. now I fix the issue.