Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #104

Closed
Dallas62 opened this issue Feb 8, 2018 · 2 comments
Closed

Cleanup #104

Dallas62 opened this issue Feb 8, 2018 · 2 comments

Comments

@Dallas62
Copy link

Dallas62 commented Feb 8, 2018

I just try cleanup method on a test database, and it result on a deletion of all updates made.

Exemple:

First doc:

{
_id: 123,
prop1: true,
prop2: 'value'
}

Update 1: prop1 true => false
Result a new document:

{
_id: 123 + timestamp,
$id: 123,
prop1: fasle
}

.all() result:

{
$id: 123,
prop1: false,
prop2: 'value'
}

Execute .cleanup(),
.all() result:

{
$id: 123,
prop1: true,
prop2: 'value'
}

And document "Update 1" (123+timestamp) as disappear from database.

@diegomr86
Copy link

Same issue here

@dawnmist
Copy link

dawnmist commented Apr 11, 2019

It does the same thing on the websites live demo (you can see it immediately in the devtools for application/idb, though you need to reload the page to see the text get updated to reflect that the edits were lost).

Since that example is one of the two live demos for the package, it should be pretty easy to use as a test case.

Edit: The error is occurring inside the cleanupDoc function:

delta-pouch/index.js

Lines 215 to 226 in 257e0c8

var undef = false;
for (var k in el.doc) {
if (typeof docs[el.doc.$id][k] === 'undefined') {
undef = true;
break;
}
}
if (undef) {
docs[el.doc.$id] = exports.merge(docs[el.doc.$id], el.doc);
} else { // duplicate update, remove
return db.remove(object);
}

This function checks whether the new doc has a field that has been set to undefined, but it doesn't check if any of the fields with values have been modified. Only when a field has been set to undefined are the differences between the old and new documents merged, resulting in any updated values to an existing field incorrectly falling through into the "duplicate update" case.

@Dallas62 Dallas62 closed this as completed Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants