Commit c0c9301e authored by Tristan Cavelier's avatar Tristan Cavelier

allDocs optimization

parent d4e4af04
...@@ -521,42 +521,42 @@ ...@@ -521,42 +521,42 @@
}; };
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; break;
} else { }
// browsing answer rows }
for (j = 0; j < answers[i].data.rows.length; j += 1) { for (i += 1; i < answers.length; i += 1) {
found = false; if (answers[i].result === "success") {
// browsing result rows // browsing answer rows
for (k = 0; k < rows.length; k += 1) { for (j = 0; j < answers[i].data.rows.length; j += 1) {
if (rows[k].id === answers[i].data.rows[j].id) { found = false;
found = true; // browsing result rows
break; for (k = 0; k < rows.length; k += 1) {
} if (rows[k].id === answers[i].data.rows[j].id) {
} found = true;
if (!found) { break;
rows.push(answers[i].data.rows[j]);
} }
} }
if (!found) {
rows.push(answers[i].data.rows[j]);
}
} }
} }
} }
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