Commit af44eae9 authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Romain Courteaud

ReplicateStorage: use bulk method when checking remote modification

parent 8a2bae4a
......@@ -309,11 +309,12 @@
}
function checkSignatureDifference(queue, source, destination, id,
conflict_force, conflict_ignore) {
conflict_force, conflict_ignore,
getMethod) {
queue
.push(function () {
return RSVP.all([
source.get(id),
getMethod(id),
context._signature_sub_storage.get(id)
]);
})
......@@ -361,6 +362,35 @@
});
}
function checkBulkSignatureDifference(queue, source, destination, id_list,
conflict_force, conflict_ignore) {
queue
.push(function () {
return source.bulk(id_list);
})
.push(function (result_list) {
var i,
sub_queue = new RSVP.Queue();
function getResult(j) {
return function (id) {
if (id !== id_list[j].parameter_list[0]) {
throw new Error("Does not access expected ID " + id);
}
return result_list[j];
};
}
for (i = 0; i < result_list.length; i += 1) {
checkSignatureDifference(sub_queue, source, destination,
id_list[i].parameter_list[0],
conflict_force, conflict_ignore,
getResult(i));
}
return sub_queue;
});
}
function pushStorage(source, destination, options) {
var queue = new RSVP.Queue();
if (!options.hasOwnProperty("use_post")) {
......@@ -377,6 +407,7 @@
var i,
local_dict = {},
new_list = [],
change_list = [],
signature_dict = {},
key;
for (i = 0; i < result_list[0].data.total_rows; i += 1) {
......@@ -419,9 +450,17 @@
if (signature_dict.hasOwnProperty(key)) {
if (local_dict.hasOwnProperty(key)) {
if (options.check_modification === true) {
checkSignatureDifference(queue, source, destination, key,
options.conflict_force,
options.conflict_ignore);
if (options.use_bulk_get === true) {
change_list.push({
method: "get",
parameter_list: [key]
});
} else {
checkSignatureDifference(queue, source, destination, key,
options.conflict_force,
options.conflict_ignore,
source.get.bind(source));
}
}
} else {
if (options.check_deletion === true) {
......@@ -430,6 +469,12 @@
}
}
}
if ((options.use_bulk_get === true) && (change_list.length !== 0)) {
checkBulkSignatureDifference(queue, source, destination,
change_list,
options.conflict_force,
options.conflict_ignore);
}
});
}
......
......@@ -2332,4 +2332,102 @@
});
});
test("bulk remote document modification", function () {
stop();
expect(5);
var id,
post_id = "123456789",
context = this;
function Storage200Bulk(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
}
Storage200Bulk.prototype.bulk = function (args) {
deepEqual(args, [{
method: "get",
parameter_list: [post_id]
}]);
return this._sub_storage.get(post_id)
.push(function (doc) {
return [doc];
});
};
Storage200Bulk.prototype.post = function (param) {
return this.put(post_id, param);
};
Storage200Bulk.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'replicatestorage200bulkremotemodification',
Storage200Bulk
);
this.jio = jIO.createJIO({
type: "replicate",
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "replicatestorage200bulkremotemodification",
sub_storage: {
type: "memory"
}
}
});
context.jio.__storage._remote_sub_storage.post({"title": "bar"})
.then(function (result) {
id = result;
return context.jio.repair();
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
title: "bar"
});
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get(id);
})
.then(function (result) {
deepEqual(result, {
hash: "6799f3ea80e325b89f19589282a343c376c1f1af"
});
})
.then(function () {
return context.jio.__storage._remote_sub_storage.put(
id,
{"title": "foo"}
);
})
.then(function (result) {
id = result;
return context.jio.repair();
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
title: "foo"
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(jIO, QUnit));
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