Commit 54f2580d authored by Vincent Bechu's avatar Vincent Bechu

replicatestorage: limit calculation hash for document

parent 4f5abd39
...@@ -34,8 +34,11 @@ ...@@ -34,8 +34,11 @@
Synchronization status is stored for each document as an local attachment. Synchronization status is stored for each document as an local attachment.
****************************************************/ ****************************************************/
function generateHash(content) { function generateHash(content, context) {
// XXX Improve performance by moving calculation to WebWorker // XXX Improve performance by moving calculation to WebWorker
if (context !== undefined && context._skip_document_hash) {
return "1";
}
return rusha.digestFromString(content); return rusha.digestFromString(content);
} }
...@@ -156,6 +159,15 @@ ...@@ -156,6 +159,15 @@
this._conflict_handling !== CONFLICT_KEEP_LOCAL) || this._conflict_handling !== CONFLICT_KEEP_LOCAL) ||
(!this._check_remote_attachment_creation && (!this._check_remote_attachment_creation &&
this._conflict_handling !== CONFLICT_KEEP_REMOTE)); this._conflict_handling !== CONFLICT_KEEP_REMOTE));
this._skip_document_hash =
this !== undefined &&
!this._check_remote_modification &&
!this._check_local_modification &&
((!this._check_local_creation &&
this._conflict_handling !== CONFLICT_KEEP_LOCAL) ||
(!this._check_remote_creation &&
this._conflict_handling !== CONFLICT_KEEP_REMOTE));
} }
ReplicateStorage.prototype.remove = function (id) { ReplicateStorage.prototype.remove = function (id) {
...@@ -704,7 +716,7 @@ ...@@ -704,7 +716,7 @@
options) { options) {
return destination.get(id) return destination.get(id)
.push(function (remote_doc) { .push(function (remote_doc) {
return [remote_doc, generateHash(stringify(remote_doc))]; return [remote_doc, generateHash(stringify(remote_doc), context)];
}, function (error) { }, function (error) {
if ((error instanceof jIO.util.jIOError) && if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) { (error.status_code === 404)) {
...@@ -826,7 +838,7 @@ ...@@ -826,7 +838,7 @@
}) })
.push(function (result_list) { .push(function (result_list) {
var doc = result_list[0], var doc = result_list[0],
local_hash = generateHash(stringify(doc)), local_hash = generateHash(stringify(doc), context),
status_hash = result_list[1].hash; status_hash = result_list[1].hash;
if (local_hash !== status_hash) { if (local_hash !== status_hash) {
......
...@@ -4677,6 +4677,130 @@ ...@@ -4677,6 +4677,130 @@
); );
}); });
test("local creation, same document id: keep remote", function () {
stop();
expect(2);
var id,
context = this;
this.jio = jIO.createJIO({
type: "replicate",
conflict_handling: 2,
check_local_modification: false,
check_local_deletion: false,
check_remote_modification: false,
check_remote_creation: false,
check_remote_deletion: false,
local_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
remote_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
}
});
context.jio.post({"title": "foobar"})
.then(function (result) {
id = result;
return context.jio.__storage._remote_sub_storage.put(
id,
{"title": "foo"}
);
})
.then(function () {
return context.jio.repair();
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get(id);
})
.then(function (result) {
deepEqual(result, {
hash: "5ea9013447539ad65de308cbd75b5826a2ae30e5"
});
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {"title": "foo"});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("remote creation, same document id: keep local", function () {
stop();
expect(2);
var id,
context = this;
this.jio = jIO.createJIO({
type: "replicate",
conflict_handling: 1,
check_local_creation: false,
check_local_modification: false,
check_local_deletion: false,
check_remote_modification: false,
check_remote_deletion: false,
local_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
remote_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
}
});
context.jio.post({"title": "foo"})
.then(function (result) {
id = result;
return context.jio.__storage._remote_sub_storage.put(
id,
{"title": "foobar"}
);
})
.then(function () {
return context.jio.repair();
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get(id);
})
.then(function (result) {
deepEqual(result, {
hash: "5ea9013447539ad65de308cbd75b5826a2ae30e5"
});
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {"title": "foo"});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// attachment replication // attachment replication
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment