Commit 86942633 authored by Bryan Kaperick's avatar Bryan Kaperick

Fixed allDocs implementation to rely more on QueryStorage's allDocs.

parent 9bf585e5
...@@ -236,7 +236,6 @@ ...@@ -236,7 +236,6 @@
attachment_promises[entry.value.name] = attachment_promises[entry.value.name] =
substorage.getAttachment(entry.id, entry.value.name); substorage.getAttachment(entry.id, entry.value.name);
} }
return RSVP.hash(attachment_promises); return RSVP.hash(attachment_promises);
}); });
}; };
...@@ -256,7 +255,6 @@ ...@@ -256,7 +255,6 @@
return substorage.putAttachment(timestamp, name, blob); return substorage.putAttachment(timestamp, name, blob);
}); });
}; };
HistoryStorage.prototype.getAttachment = function (id, name) { HistoryStorage.prototype.getAttachment = function (id, name) {
if (this._include_revisions) { if (this._include_revisions) {
...@@ -335,10 +333,11 @@ ...@@ -335,10 +333,11 @@
HistoryStorage.prototype.repair = function () { HistoryStorage.prototype.repair = function () {
return this._sub_storage.repair.apply(this._sub_storage, arguments); return this._sub_storage.repair.apply(this._sub_storage, arguments);
}; };
HistoryStorage.prototype.hasCapacity = function () { HistoryStorage.prototype.hasCapacity = function (name) {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments); return name === 'list' || name === 'include';
}; };
HistoryStorage.prototype.buildQuery = function (options) { HistoryStorage.prototype.buildQuery = function (options) {
// Set default values // Set default values
if (options === undefined) {options = {}; } if (options === undefined) {options = {}; }
...@@ -348,41 +347,22 @@ ...@@ -348,41 +347,22 @@
if (options.include_revisions === undefined) { if (options.include_revisions === undefined) {
options.include_revisions = false; options.include_revisions = false;
} }
options.sort_on.push(["timestamp", "descending"]);
options.query = jIO.QueryFactory.create(options.query); options.query = jIO.QueryFactory.create(options.query);
var meta_options, var meta_options = {
include_revs = this._include_revisions,
doc_id_name,
timestamp_name;
// Query for all edits
meta_options = {
query: "", query: "",
sort_on: options.sort_on, sort_on: [["timestamp", "descending"]],
select_list: ["doc", "op", "doc_id"] select_list: ["doc", "op", "doc_id"]
}; },
include_revs = this._include_revisions;
return this._sub_storage.allDocs(meta_options) return this._sub_storage.allDocs(meta_options)
.push(function (results) { .push(function (results) {
results = results.data.rows; results = results.data.rows;
var seen = {}, var seen = {},
query_matches,
docs_to_query, docs_to_query,
i; i;
doc_id_name = "_doc_id";
timestamp_name = "_timestamp";
for (i = 0; i < results.length; i += 1) {
if (results[i].value.op === "put") {
while (results[i].value.doc.hasOwnProperty(doc_id_name)) {
doc_id_name = "_" + doc_id_name;
}
while (results[i].value.doc.hasOwnProperty(timestamp_name)) {
timestamp_name = "_" + timestamp_name;
}
}
}
if (include_revs) { if (include_revs) {
// We only query on versions mapping to puts or putAttachments // We only query on versions mapping to puts or putAttachments
...@@ -412,6 +392,8 @@ ...@@ -412,6 +392,8 @@
} }
return docum; return docum;
} }
// If most recent metadata edit before the attachment edit
// was a remove, then leave doc empty
if (results[i].value.op === "remove") { if (results[i].value.op === "remove") {
return docum; return docum;
} }
...@@ -455,7 +437,7 @@ ...@@ -455,7 +437,7 @@
} }
return docum; return docum;
} }
if (results[i].value.doc_id === "remove") { if (results[i].value.op === "remove") {
// If most recent edit on document was a remove before // If most recent edit on document was a remove before
// this attachment, then don't include attachment in query // this attachment, then don't include attachment in query
return false; return false;
...@@ -467,45 +449,30 @@ ...@@ -467,45 +449,30 @@
return false; return false;
}); });
} }
docs_to_query = results docs_to_query = results
// Filter out all docs flagged as false in previous map call // Filter out all docs flagged as false in previous map call
.filter(function (docum) { .filter(function (docum) {
return docum; return docum;
}) })
// Put into correct format to be passed back to query storage
.map(function (docum) { .map(function (docum) {
// Save timestamp and id information for retrieval at the end of docum.doc = docum.value.doc;
// buildQuery docum.id = docum.value.doc_id;
docum.value.doc[timestamp_name] = docum.id; delete docum.value.doc_id;
docum.value.doc[doc_id_name] = docum.value.doc_id; delete docum.value.op;
return docum.value.doc;
});
// Return timestamp and id information from query if (options.include_docs) {
options.select_list.push(doc_id_name); docum.doc = docum.value.doc;
options.select_list.push(timestamp_name); } else {
docum.doc = {};
}
// Sort on timestamp with updated timestamp_name docum.value = {};
options.sort_on[options.sort_on.length - 1] = [ return docum;
timestamp_name, "descending"
];
query_matches = options.query.exec(docs_to_query, options);
return query_matches;
})
// Format the results of the query, and return
.push(function (query_matches) {
return query_matches.map(function (docum) {
var doc_id = docum[doc_id_name],
time = docum[timestamp_name];
delete docum[timestamp_name];
delete docum[doc_id_name];
return {
doc: {},
value: docum,
id: doc_id,
timestamp: time
};
}); });
return docs_to_query;
}); });
}; };
......
This diff is collapsed.
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