pouchdb-seamless-auth icon indicating copy to clipboard operation
pouchdb-seamless-auth copied to clipboard

Problem with 'replication'

Open AidanNichol opened this issue 8 years ago • 2 comments

I'm struggling with a couple of issues that aren't working as I expected and so dug into the code a little and noticed a line that will eventually fail at around line 166 & 168 in startReplication.

There is a check to see if replication is needed in a specific direction e.g. if (remoteDoc._rev > localDoc._rev) { When a document revision goes from 9-xxxxxxxx to 10-xxxxxxx the checks will give the opposite of what is expected.

It needs a function to extract the revision value and to use that in the compares e.g.

function getRev(doc){
    return parseInt(doc._rev.split('-')[0]);
}
...
if (getRev(remoteDoc) > getRev(localDoc)) {

AidanNichol avatar Sep 11 '16 12:09 AidanNichol

Nice find. The whole semi-replication mechanism is a bit sketchy, but this would at least be an improvement. PR welcome.

marten-de-vries avatar Nov 26 '16 11:11 marten-de-vries

I'll look into creating a PR for this.

I know what you mean by saying that the semi-replication mechanism is a bit sketchy. I found that it works fine for the first use but updates are very hit and miss e.g. update the roles on the server and it fails because of a lack of permissions. I’ve been working on a clone and solved it by always deleting the existing local record and compacting if updates are needed so it always works like the first time.

I also found a strange situation where I would signin, get the session and then try to read the doc to get custom user fields and it give document not found because the replication hadn’t completed. I’ve changed the signing/replication part to return promises so the signing doesn’t successfully complete until the local doc exists.

It feels a bit kluge but seems to work OK for me. I’ll try to find time to dig a little deeper and make some PRs

AidanNichol avatar Nov 26 '16 14:11 AidanNichol