Commit 84cba972 authored by Romain Courteaud's avatar Romain Courteaud

ReplicateStorage: fetch signature hash with allDocs only

parent 7e1935d5
...@@ -56,9 +56,12 @@ ...@@ -56,9 +56,12 @@
stringify(this._query_options) stringify(this._query_options)
); );
this._signature_sub_storage = jIO.createJIO({ this._signature_sub_storage = jIO.createJIO({
type: "query",
sub_storage: {
type: "document", type: "document",
document_id: this._signature_hash, document_id: this._signature_hash,
sub_storage: spec.signature_storage || spec.local_sub_storage sub_storage: spec.signature_storage || spec.local_sub_storage
}
}); });
this._use_remote_post = spec.use_remote_post || false; this._use_remote_post = spec.use_remote_post || false;
...@@ -805,31 +808,14 @@ ...@@ -805,31 +808,14 @@
source, destination, id, source, destination, id,
conflict_force, conflict_revert, conflict_force, conflict_revert,
conflict_ignore, conflict_ignore,
is_creation, is_modification, status_hash,
getMethod, options) { getMethod, options) {
queue queue
.push(function () { .push(function () {
// Optimisation to save a get call to signature storage return getMethod(id);
if (is_creation === true) {
return RSVP.all([
getMethod(id),
{hash: null}
]);
}
if (is_modification === true) {
return RSVP.all([
getMethod(id),
context._signature_sub_storage.get(id)
]);
}
throw new jIO.util.jIOError("Unexpected call of"
+ " checkSignatureDifference",
409);
}) })
.push(function (result_list) { .push(function (doc) {
var doc = result_list[0], var local_hash = generateHash(stringify(doc));
local_hash = generateHash(stringify(doc)),
status_hash = result_list[1].hash;
if (local_hash !== status_hash) { if (local_hash !== status_hash) {
return checkAndPropagate(context, skip_document_dict, return checkAndPropagate(context, skip_document_dict,
...@@ -859,6 +845,7 @@ ...@@ -859,6 +845,7 @@
signature_dict = {}, signature_dict = {},
is_modification, is_modification,
is_creation, is_creation,
status_hash,
key, key,
queue = new RSVP.Queue(); queue = new RSVP.Queue();
for (i = 0; i < source_allDocs.data.total_rows; i += 1) { for (i = 0; i < source_allDocs.data.total_rows; i += 1) {
...@@ -872,7 +859,8 @@ ...@@ -872,7 +859,8 @@
if (!skip_document_dict.hasOwnProperty( if (!skip_document_dict.hasOwnProperty(
signature_allDocs.data.rows[i].id signature_allDocs.data.rows[i].id
)) { )) {
signature_dict[signature_allDocs.data.rows[i].id] = i; signature_dict[signature_allDocs.data.rows[i].id] =
signature_allDocs.data.rows[i].value.hash;
} }
} }
for (key in local_dict) { for (key in local_dict) {
...@@ -881,6 +869,13 @@ ...@@ -881,6 +869,13 @@
&& options.check_modification; && options.check_modification;
is_creation = !signature_dict.hasOwnProperty(key) is_creation = !signature_dict.hasOwnProperty(key)
&& options.check_creation; && options.check_creation;
if (is_creation === true) {
status_hash = null;
} else if (is_modification === true) {
status_hash = signature_dict[key];
}
if (is_modification === true || is_creation === true) { if (is_modification === true || is_creation === true) {
argument_list.push([undefined, context, skip_document_dict, argument_list.push([undefined, context, skip_document_dict,
source, destination, source, destination,
...@@ -888,7 +883,7 @@ ...@@ -888,7 +883,7 @@
options.conflict_force, options.conflict_force,
options.conflict_revert, options.conflict_revert,
options.conflict_ignore, options.conflict_ignore,
is_creation, is_modification, status_hash,
source.get.bind(source), source.get.bind(source),
options]); options]);
} }
...@@ -949,14 +944,16 @@ ...@@ -949,14 +944,16 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
// Ensure that the document storage is usable // Ensure that the document storage is usable
return context._signature_sub_storage.__storage._sub_storage.get( return context._signature_sub_storage.__storage._sub_storage
.__storage._sub_storage.get(
context._signature_hash context._signature_hash
); );
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) && if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) { (error.status_code === 404)) {
return context._signature_sub_storage.__storage._sub_storage.put( return context._signature_sub_storage.__storage._sub_storage
.__storage._sub_storage.put(
context._signature_hash, context._signature_hash,
{} {}
); );
...@@ -989,7 +986,9 @@ ...@@ -989,7 +986,9 @@
context._check_remote_modification || context._check_remote_modification ||
context._check_remote_creation || context._check_remote_creation ||
context._check_remote_deletion) { context._check_remote_deletion) {
return context._signature_sub_storage.allDocs(); return context._signature_sub_storage.allDocs({
select_list: ['hash']
});
} }
}) })
......
...@@ -111,14 +111,25 @@ ...@@ -111,14 +111,25 @@
"_replicate_7209dfbcaff00f6637f939fdd71fa896793ed385"); "_replicate_7209dfbcaff00f6637f939fdd71fa896793ed385");
ok(jio.__storage._signature_sub_storage instanceof jio.constructor); ok(jio.__storage._signature_sub_storage instanceof jio.constructor);
equal(jio.__storage._signature_sub_storage.__type, "document"); equal(jio.__storage._signature_sub_storage.__type, "query");
equal(jio.__storage._signature_sub_storage.__storage._document_id, ok(jio.__storage._signature_sub_storage
.__storage._sub_storage instanceof jio.constructor);
equal(jio.__storage._signature_sub_storage
.__storage._sub_storage.__type, "document");
equal(jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._document_id,
jio.__storage._signature_hash); jio.__storage._signature_hash);
ok(jio.__storage._signature_sub_storage.__storage._sub_storage ok(jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._sub_storage
instanceof jio.constructor); instanceof jio.constructor);
equal(jio.__storage._signature_sub_storage.__storage._sub_storage.__type, equal(jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._sub_storage.__type,
"replicatestorage200"); "replicatestorage200");
}); });
...@@ -175,8 +186,28 @@ ...@@ -175,8 +186,28 @@
equal(jio.__storage._check_remote_attachment_deletion, true); equal(jio.__storage._check_remote_attachment_deletion, true);
equal(jio.__storage._check_remote_attachment_modification, true); equal(jio.__storage._check_remote_attachment_modification, true);
equal(jio.__storage._signature_sub_storage.__storage._sub_storage.__type, ok(jio.__storage._signature_sub_storage instanceof jio.constructor);
equal(jio.__storage._signature_sub_storage.__type, "query");
ok(jio.__storage._signature_sub_storage
.__storage._sub_storage instanceof jio.constructor);
equal(jio.__storage._signature_sub_storage
.__storage._sub_storage.__type, "document");
equal(jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._document_id,
jio.__storage._signature_hash);
ok(jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._sub_storage
instanceof jio.constructor);
equal(jio.__storage._signature_sub_storage
.__storage._sub_storage
.__storage._sub_storage.__type,
"signaturestorage2713"); "signaturestorage2713");
equal(jio.__storage._signature_hash, equal(jio.__storage._signature_hash,
"_replicate_11881e431308c0ec8c0e6430be98db380e1b92f8"); "_replicate_11881e431308c0ec8c0e6430be98db380e1b92f8");
}); });
......
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