Commit a1d4c506 authored by Bryan Kaperick's avatar Bryan Kaperick

Changed behavior of allDocs with include_revisions.

parent ee3050e4
...@@ -240,8 +240,6 @@ ...@@ -240,8 +240,6 @@
}; };
HistoryStorage.prototype.allAttachments = function (id) { HistoryStorage.prototype.allAttachments = function (id) {
// XXX: allAttachments with timestamp:
// should return all non-removed attachments at this point in time
var substorage = this._sub_storage, var substorage = this._sub_storage,
query_obj, query_obj,
query_removed_check, query_removed_check,
...@@ -251,6 +249,8 @@ ...@@ -251,6 +249,8 @@
include_revs = this._include_revisions, include_revs = this._include_revisions,
have_seen_id = false; have_seen_id = false;
// id is a timestamp, and allAttachments will return attachment versions
// up-to-and-including those made at time id
if (include_revs) { if (include_revs) {
query_doc_id = new SimpleQuery({ query_doc_id = new SimpleQuery({
operator: "<=", operator: "<=",
...@@ -290,7 +290,6 @@ ...@@ -290,7 +290,6 @@
] ]
}); });
options_remcheck = { options_remcheck = {
query: query_removed_check, query: query_removed_check,
select_list: ["op", "timestamp"], select_list: ["op", "timestamp"],
...@@ -388,6 +387,8 @@ ...@@ -388,6 +387,8 @@
}; };
HistoryStorage.prototype.getAttachment = function (id, name) { HistoryStorage.prototype.getAttachment = function (id, name) {
// In this case, id is a timestamp, so return attachment version at that
// time
if (this._include_revisions) { if (this._include_revisions) {
return this._sub_storage.getAttachment(id, name) return this._sub_storage.getAttachment(id, name)
.push(undefined, function (error) { .push(undefined, function (error) {
...@@ -467,7 +468,10 @@ ...@@ -467,7 +468,10 @@
}; };
HistoryStorage.prototype.hasCapacity = function (name) { HistoryStorage.prototype.hasCapacity = function (name) {
return name === 'list' || name === 'include'; return name === 'list' ||
name === 'include' ||
name === 'query' ||
name === 'select';
}; };
HistoryStorage.prototype.buildQuery = function (options) { HistoryStorage.prototype.buildQuery = function (options) {
...@@ -477,7 +481,6 @@ ...@@ -477,7 +481,6 @@
if (options.sort_on === undefined) {options.sort_on = []; } if (options.sort_on === undefined) {options.sort_on = []; }
if (options.select_list === undefined) {options.select_list = []; } if (options.select_list === undefined) {options.select_list = []; }
options.query = jIO.QueryFactory.create(options.query); options.query = jIO.QueryFactory.create(options.query);
var meta_options = { var meta_options = {
query: "", query: "",
sort_on: [["timestamp", "descending"]], sort_on: [["timestamp", "descending"]],
...@@ -485,6 +488,10 @@ ...@@ -485,6 +488,10 @@
}, },
include_revs = this._include_revisions; include_revs = this._include_revisions;
if (include_revs) {// && options.query.key === "doc_id") {
meta_options.query = options.query;
}
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;
...@@ -588,23 +595,19 @@ ...@@ -588,23 +595,19 @@
// Put into correct format to be passed back to query storage // Put into correct format to be passed back to query storage
.map(function (docum) { .map(function (docum) {
docum.doc = docum.value.doc;
if (include_revs) { if (include_revs) {
docum.id = docum.value.timestamp; docum.id = docum.value.timestamp;
//docum.doc = docum.value.doc;
} else { } else {
docum.id = docum.value.doc_id; docum.id = docum.value.doc_id;
//docum.doc = docum.value.doc;
} }
delete docum.value.doc_id; delete docum.value.doc_id;
delete docum.value.timestamp; delete docum.value.timestamp;
delete docum.value.op; delete docum.value.op;
docum.value = docum.value.doc;
if (options.include_docs) { //docum.value = {};
docum.doc = docum.value.doc;
} else {
docum.doc = {};
}
docum.value = {};
return docum; return docum;
}); });
return docs_to_query; return docs_to_query;
......
...@@ -2265,6 +2265,63 @@ ...@@ -2265,6 +2265,63 @@
.always(function () {start(); }); .always(function () {start(); });
}); });
test("allDocs with include_revisions only one document",
function () {
stop();
expect(1);
var jio = this.jio,
history = this.history,
timestamps,
not_history = this.not_history;
jio.put("doc a", {title: "foo0"})
.push(function () {
return jio.put("doc a", {title: "foo1"});
})
.push(function () {
return jio.put("doc b", {title: "bar0"});
})
.push(function () {
return jio.put("doc b", {title: "bar1"});
})
.push(function () {
return not_history.allDocs({
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
});
})
.push(function () {
return history.allDocs({
query: 'doc_id: "doc a"',
select_list: ["title"]
});
})
.push(function (results) {
deepEqual(results.data.rows, [
{
id: timestamps[1],
doc: {},
value: {title: "foo1"}
},
{
id: timestamps[0],
doc: {},
value: {title: "foo0"}
}],
"Only specified document revision history is returned"
);
})
.fail(function (error) {
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
});
test("Parallel edits will not break anything", test("Parallel edits will not break anything",
function () { function () {
stop(); stop();
......
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