Commit c0c9301e authored by Tristan Cavelier's avatar Tristan Cavelier

allDocs optimization

parent d4e4af04
...@@ -521,23 +521,23 @@ ...@@ -521,23 +521,23 @@
}; };
ReplicateStorage.prototype.allDocs = function (command, param, option) { ReplicateStorage.prototype.allDocs = function (command, param, option) {
/*jslint unparam: true */
var promise_list = [], index, length = this._storage_list.length; var promise_list = [], index, length = this._storage_list.length;
for (index = 0; index < length; index += 1) { for (index = 0; index < length; index += 1) {
promise_list[index] = promise_list[index] =
success(command.storage(this._storage_list[index]).allDocs(option)); success(command.storage(this._storage_list[index]).allDocs(option));
} }
sequence([function () { all(promise_list).then(function (answers) {
return all(promise_list);
}, function (answers) {
// merge responses // merge responses
var i, j, k, found, rows; var i, j, k, found, rows;
// browsing answers // browsing answers
for (i = 0; i < answers.length; i += 1) { for (i = 0; i < answers.length; i += 1) {
if (answers[i].result === "success") { if (answers[i].result === "success") {
if (!rows) {
rows = answers[i].data.rows; rows = answers[i].data.rows;
} else { break;
}
}
for (i += 1; i < answers.length; i += 1) {
if (answers[i].result === "success") {
// browsing answer rows // browsing answer rows
for (j = 0; j < answers[i].data.rows.length; j += 1) { for (j = 0; j < answers[i].data.rows.length; j += 1) {
found = false; found = false;
...@@ -554,9 +554,9 @@ ...@@ -554,9 +554,9 @@
} }
} }
} }
}
return {"data": {"total_rows": (rows || []).length, "rows": rows || []}}; return {"data": {"total_rows": (rows || []).length, "rows": rows || []}};
}, [command.success, command.error]]); }).then(command.success, command.error, command.notify);
/*jslint unparam: true */
}; };
ReplicateStorage.prototype.check = function (command, param, option) { ReplicateStorage.prototype.check = function (command, param, option) {
......
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