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;
}) })
.map(function (docum) {
// Save timestamp and id information for retrieval at the end of
// buildQuery
docum.value.doc[timestamp_name] = docum.id;
docum.value.doc[doc_id_name] = docum.value.doc_id;
return docum.value.doc;
});
// Return timestamp and id information from query // Put into correct format to be passed back to query storage
options.select_list.push(doc_id_name); .map(function (docum) {
options.select_list.push(timestamp_name); docum.doc = docum.value.doc;
docum.id = docum.value.doc_id;
delete docum.value.doc_id;
delete docum.value.op;
if (options.include_docs) {
docum.doc = docum.value.doc;
} 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" });
]; return docs_to_query;
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
};
});
}); });
}; };
......
...@@ -22,6 +22,115 @@ ...@@ -22,6 +22,115 @@
}); });
} }
module("HistoryStorage.post", {
setup: function () {
// create storage of type "history" with memory as substorage
var dbname = "db_" + Date.now();
this.jio = jIO.createJIO({
type: "uuid",
sub_storage: {
type: "query",
sub_storage: {
type: "history",
sub_storage: {
type: "query",
sub_storage: {
type: "indexeddb",
database: dbname
}
}
}
}
});
this.history = jIO.createJIO({
type: "uuid",
sub_storage: {
type: "query",
sub_storage: {
type: "history",
include_revisions: true,
sub_storage: {
type: "query",
sub_storage: {
type: "indexeddb",
database: dbname
}
}
}
}
});
this.not_history = jIO.createJIO({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: dbname
}
}
});
}
});
test("Verifying simple post works",
function () {
stop();
expect(2);
var jio = this.jio,
history = this.history,
not_history = this.not_history,
//timestamps,
id;
return jio.post({title: "foo0"})
.push(function (result) {
id = result;
return jio.put(result, {title: "foo1"});
})
.push(function (result) {
return jio.get(result);
})
.push(function (res) {
deepEqual(res, {
title: "foo1"
}, "history storage only retrieves latest version");
})
.push(function () {
return not_history.allDocs({
select_list: ["timestamp"]
});
})
.push(function () {
return history.allDocs({select_list: ["title"]});
})
.push(function (res) {
deepEqual(res.data.rows, [
{
value: {
title: "foo1"
},
doc: {},
//timestamp: timestamps[1],
id: id
},
{
value: {
title: "foo0"
},
doc: {},
//timestamp: timestamps[0],
id: id
}
],
"Two revisions logged with correct metadata");
})
.fail(function (error) {
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Attachments // Attachments
...@@ -36,28 +145,34 @@ ...@@ -36,28 +145,34 @@
this.blob3 = new Blob(['ccc']); this.blob3 = new Blob(['ccc']);
this.other_blob = new Blob(['1']); this.other_blob = new Blob(['1']);
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "history", type: "query",
sub_storage: { sub_storage: {
type: "query", type: "history",
sub_storage: { sub_storage: {
type: "uuid", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "uuid",
database: dbname sub_storage: {
type: "indexeddb",
database: dbname
}
} }
} }
} }
}); });
this.history = jIO.createJIO({ this.history = jIO.createJIO({
type: "history", type: "query",
include_revisions: true,
sub_storage: { sub_storage: {
type: "query", type: "history",
include_revisions: true,
sub_storage: { sub_storage: {
type: "uuid", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "uuid",
database: dbname sub_storage: {
type: "indexeddb",
database: dbname
}
} }
} }
} }
...@@ -556,28 +671,34 @@ ...@@ -556,28 +671,34 @@
// create storage of type "history" with memory as substorage // create storage of type "history" with memory as substorage
var dbname = "db_" + Date.now(); var dbname = "db_" + Date.now();
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "history", type: "query",
sub_storage: { sub_storage: {
type: "query", type: "history",
sub_storage: { sub_storage: {
type: "uuid", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "uuid",
database: dbname sub_storage: {
type: "indexeddb",
database: dbname
}
} }
} }
} }
}); });
this.history = jIO.createJIO({ this.history = jIO.createJIO({
type: "history", type: "query",
include_revisions: true,
sub_storage: { sub_storage: {
type: "query", type: "history",
include_revisions: true,
sub_storage: { sub_storage: {
type: "uuid", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "uuid",
database: dbname sub_storage: {
type: "indexeddb",
database: dbname
}
} }
} }
} }
...@@ -599,9 +720,7 @@ ...@@ -599,9 +720,7 @@
function () { function () {
stop(); stop();
expect(4); expect(4);
var jio = this.jio, var jio = this.jio;
not_history = this.not_history,
timestamps;
jio.remove("doc") jio.remove("doc")
.push(function () { .push(function () {
...@@ -622,17 +741,6 @@ ...@@ -622,17 +741,6 @@
"HistoryStorage: cannot find object 'doc' (removed)", "HistoryStorage: cannot find object 'doc' (removed)",
"Error is handled by history storage before reaching console"); "Error is handled by history storage before reaching console");
}) })
.push(function () {
return not_history.allDocs({
select_list: ["timestamp"],
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.value.timestamp;
});
})
.push(function () { .push(function () {
return jio.allDocs({select_list: ["title"]}); return jio.allDocs({select_list: ["title"]});
}) })
...@@ -641,9 +749,9 @@ ...@@ -641,9 +749,9 @@
{ {
id: "doc2", id: "doc2",
value: {title: "foo"}, value: {title: "foo"},
doc: {}, //timestamp: timestamps[1],
timestamp: timestamps[1] doc: {}
}], "DOcument that was removed before being put is not retrieved"); }], "Document that was removed before being put is not retrieved");
}) })
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
...@@ -657,8 +765,7 @@ ...@@ -657,8 +765,7 @@
stop(); stop();
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history;
timestamps;
jio.remove("doc") jio.remove("doc")
.push(function () { .push(function () {
...@@ -672,16 +779,6 @@ ...@@ -672,16 +779,6 @@
title: "foo" title: "foo"
}, "A put was the most recent edit on 'doc'"); }, "A put was the most recent edit on 'doc'");
}) })
.push(function () {
return history.allDocs({
select_list: ["timestamp"]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.timestamp;
});
})
.push(function () { .push(function () {
return history.allDocs({select_list: ["title"]}); return history.allDocs({select_list: ["title"]});
}) })
...@@ -690,14 +787,14 @@ ...@@ -690,14 +787,14 @@
{ {
id: "doc", id: "doc",
value: {title: "foo"}, value: {title: "foo"},
doc: {}, //timestamp: timestamps[0],
timestamp: timestamps[0] doc: {}
}, },
{ {
id: "doc", id: "doc",
value: {}, value: {},
doc: {}, //timestamp: timestamps[1],
timestamp: timestamps[1] doc: {}
}], "DOcument that was removed before being put is not retrieved"); }], "DOcument that was removed before being put is not retrieved");
}) })
.fail(function (error) { .fail(function (error) {
...@@ -713,14 +810,15 @@ ...@@ -713,14 +810,15 @@
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history,
timestamp; timestamp;
jio.put("doc", {title: "foo"}) jio.put("doc", {title: "foo"})
.push(function () { .push(function () {
return history.allDocs(); return not_history.allDocs();
}) })
.push(function (res) { .push(function (res) {
timestamp = res.data.rows[0].timestamp; timestamp = res.data.rows[0].id;
return history.put(timestamp, {key: "val"}); return history.put(timestamp, {key: "val"});
}) })
.push(function () { .push(function () {
...@@ -779,7 +877,7 @@ ...@@ -779,7 +877,7 @@
stop(); stop();
expect(6); expect(6);
var jio = this.jio, var jio = this.jio,
history = this.history, not_history = this.not_history,
timestamp; timestamp;
jio.put("not_doc", {}) jio.put("not_doc", {})
.push(function () { .push(function () {
...@@ -799,32 +897,14 @@ ...@@ -799,32 +897,14 @@
"Error is handled by history storage before reaching console"); "Error is handled by history storage before reaching console");
}) })
.push(function () { .push(function () {
return history.allDocs(); return not_history.allDocs();
}) })
.push(function (results) { .push(function (results) {
timestamp = results.data.rows[0].timestamp; timestamp = results.data.rows[0].id;
return jio.get(timestamp); return jio.get(timestamp);
}) })
.push(function () { .push(function () {
ok(false, "This statement should not be reached"); ok(false, "This statement should not be reached");
}, function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
404,
"Correct status code for getting a non-existent document"
);
deepEqual(error.message,
"HistoryStorage: cannot find object '" + timestamp + "'",
"Error is handled by history storage before reaching console");
})
/**
* XXX: I don't think this test is necessary
.push(function () {
return history.get("doc");
})
.push(function (res) {
console.log(res);
ok(false, "This statement should not be reached");
}, function (error) { }, function (error) {
//console.log(error); //console.log(error);
ok(error instanceof jIO.util.jIOError, "Correct type of error"); ok(error instanceof jIO.util.jIOError, "Correct type of error");
...@@ -833,10 +913,9 @@ ...@@ -833,10 +913,9 @@
"Correct status code for getting a non-existent document" "Correct status code for getting a non-existent document"
); );
deepEqual(error.message, deepEqual(error.message,
"HistoryStorage: cannot find object 'doc'", "HistoryStorage: cannot find object '" + timestamp + "'",
"Error is handled by history storage before reaching console"); "Error is handled by history storage before reaching console");
}) })
**/
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
...@@ -1093,6 +1172,7 @@ ...@@ -1093,6 +1172,7 @@
stop(); stop();
expect(4); expect(4);
var jio = this.jio, var jio = this.jio,
not_history = this.not_history,
history = this.history, history = this.history,
blob = new Blob(['a']), blob = new Blob(['a']),
edit_log; edit_log;
...@@ -1108,20 +1188,22 @@ ...@@ -1108,20 +1188,22 @@
return jio.get("doc"); return jio.get("doc");
}) })
.push(function (res) { .push(function (res) {
deepEqual(res, {title: "foo0"}); deepEqual(res,
return history.allDocs({select_list: ["title"]}); {title: "foo0"},
"Correct information returned");
return not_history.allDocs({select_list: ["title"]});
}) })
.push(function (results) { .push(function (results) {
edit_log = results.data.rows; edit_log = results.data.rows;
return history.get(edit_log[0].timestamp); return history.get(edit_log[0].id);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, {title: "foo0"}); deepEqual(result, {title: "foo0"});
return history.get(edit_log[1].timestamp); return history.get(edit_log[1].id);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, {title: "foo0"}); deepEqual(result, {title: "foo0"});
return history.get(edit_log[2].timestamp); return history.get(edit_log[2].id);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, {title: "foo0"}); deepEqual(result, {title: "foo0"});
...@@ -1141,30 +1223,36 @@ ...@@ -1141,30 +1223,36 @@
module("HistoryStorage.allDocs", { module("HistoryStorage.allDocs", {
setup: function () { setup: function () {
// create storage of type "history" with memory as substorage // create storage of type "history" with memory as substorage
var dbname = "db_" + Date.now(); this.dbname = "db_" + Date.now();
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "history", type: "uuid",
sub_storage: { sub_storage: {
type: "query", type: "query",
sub_storage: { sub_storage: {
type: "uuid", type: "history",
sub_storage: { sub_storage: {
type: "indexeddb", type: "query",
database: dbname sub_storage: {
type: "indexeddb",
database: this.dbname
}
} }
} }
} }
}); });
this.history = jIO.createJIO({ this.history = jIO.createJIO({
type: "history", type: "uuid",
include_revisions: true,
sub_storage: { sub_storage: {
type: "query", type: "query",
sub_storage: { sub_storage: {
type: "uuid", type: "history",
include_revisions: true,
sub_storage: { sub_storage: {
type: "indexeddb", type: "query",
database: dbname sub_storage: {
type: "indexeddb",
database: this.dbname
}
} }
} }
} }
...@@ -1175,7 +1263,7 @@ ...@@ -1175,7 +1263,7 @@
type: "uuid", type: "uuid",
sub_storage: { sub_storage: {
type: "indexeddb", type: "indexeddb",
database: dbname database: this.dbname
} }
} }
}); });
...@@ -1223,26 +1311,27 @@ ...@@ -1223,26 +1311,27 @@
deepEqual(results.data.rows[0], { deepEqual(results.data.rows[0], {
doc: {}, doc: {},
value: {}, value: {},
id: "doc", //timestamp: timestamp,
timestamp: timestamp id: "doc"
}, },
"Correct document format is returned." "Correct document format is returned."
); );
return not_history.allDocs(); return not_history.allDocs();
}) })
.push(function (results) { .push(function (results) {
timestamp = results.data.rows[0].id;
equal(results.data.total_rows, equal(results.data.total_rows,
1, 1,
"Exactly one result returned"); "Exactly one result returned");
return not_history.get(results.data.rows[0].id); return not_history.get(timestamp);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, { deepEqual(result, {
timestamp: timestamp,
doc_id: "doc", doc_id: "doc",
doc: { doc: {
title: "version0" title: "version0"
}, },
timestamp: timestamp,
op: "put" op: "put"
}, },
"When a different type of storage queries historystorage, all " + "When a different type of storage queries historystorage, all " +
...@@ -1256,36 +1345,27 @@ ...@@ -1256,36 +1345,27 @@
.always(function () {start(); }); .always(function () {start(); });
}); });
test("Putting doc with _doc_id and _timestamp properties" + test("Putting doc with troublesome properties and retrieving with allDocs",
"and retrieving them with allDocs",
function () { function () {
stop(); stop();
expect(1); expect(1);
var jio = this.jio, var jio = this.jio;
not_history = this.not_history,
timestamp;
jio.put("doc", { jio.put("doc", {
title: "version0", title: "version0",
_doc_id: "bar", doc_id: "bar",
__doc_id: "bar2", _doc_id: "bar2",
___doc_id: "bar3", timestamp: "foo",
_timestamp: "foo", _timestamp: "foo2",
____timestamp: "foo2" id: "baz",
_id: "baz2",
__id: "baz3",
op: "zop"
}) })
.push(function () {
return not_history.allDocs({
query: "doc_id: doc",
select_list: ["timestamp"]
});
})
.push(function (results) {
timestamp = results.data.rows[0].value.timestamp;
})
.push(function () { .push(function () {
return jio.allDocs({ return jio.allDocs({
query: "title: version0 AND _timestamp: >= 0", query: "title: version0 AND _timestamp: >= 0",
select_list: ["title", "_doc_id", "__doc_id", "___doc_id", select_list: ["title", "doc_id", "_doc_id", "timestamp",
"_timestamp", "____timestamp"] "_timestamp", "id", "_id", "__id", "op"]
}); });
}) })
.push(function (results) { .push(function (results) {
...@@ -1293,17 +1373,20 @@ ...@@ -1293,17 +1373,20 @@
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
//timestamp: timestamp,
value: { value: {
title: "version0", title: "version0",
_doc_id: "bar", doc_id: "bar",
__doc_id: "bar2", _doc_id: "bar2",
___doc_id: "bar3", timestamp: "foo",
_timestamp: "foo", _timestamp: "foo2",
____timestamp: "foo2" id: "baz",
}, _id: "baz2",
timestamp: timestamp __id: "baz3",
op: "zop"
}
}], }],
"_doc_id properties are not overwritten in allDocs call"); "Poorly-named properties are not overwritten in allDocs call");
}) })
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
...@@ -1393,8 +1476,8 @@ ...@@ -1393,8 +1476,8 @@
subtitle: "subvers2" subtitle: "subvers2"
}, },
doc: {}, doc: {},
id: "doc", //timestamp: timestamps[2],
timestamp: timestamps[2] id: "doc"
}, },
"Correct document format is returned." "Correct document format is returned."
); );
...@@ -1416,8 +1499,8 @@ ...@@ -1416,8 +1499,8 @@
title: "version2", title: "version2",
subtitle: "subvers2" subtitle: "subvers2"
}, },
doc: {}, //timestamp: timestamps[2],
timestamp: timestamps[2] doc: {}
}, },
{ {
id: "doc", id: "doc",
...@@ -1425,8 +1508,8 @@ ...@@ -1425,8 +1508,8 @@
title: "version1", title: "version1",
subtitle: "subvers1" subtitle: "subvers1"
}, },
doc: {}, //timestamp: timestamps[1],
timestamp: timestamps[1] doc: {}
}, },
{ {
id: "doc", id: "doc",
...@@ -1434,8 +1517,8 @@ ...@@ -1434,8 +1517,8 @@
title: "version0", title: "version0",
subtitle: "subvers0" subtitle: "subvers0"
}, },
doc: {}, //timestamp: timestamps[0],
timestamp: timestamps[0] doc: {}
} }
], "Full version history is included."); ], "Full version history is included.");
...@@ -1550,14 +1633,14 @@ ...@@ -1550,14 +1633,14 @@
{ {
id: "doc_c", id: "doc_c",
value: {}, value: {},
doc: {}, //timestamp: timestamps[5],
timestamp: timestamps[5] doc: {}
}, },
{ {
id: "doc_a", id: "doc_a",
value: {}, value: {},
doc: {}, //timestamp: timestamps[1],
timestamp: timestamps[1] doc: {}
} }
], ],
"Empty query returns latest revisions (and no removed documents)"); "Empty query returns latest revisions (and no removed documents)");
...@@ -1582,8 +1665,6 @@ ...@@ -1582,8 +1665,6 @@
stop(); stop();
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
not_history = this.not_history,
timestamps,
docs = [ docs = [
{ {
"date": 1, "date": 1,
...@@ -1616,16 +1697,6 @@ ...@@ -1616,16 +1697,6 @@
.push(function () { .push(function () {
return putFullDoc(jio, "third_doc", docs[2], "data", blobs[2]); // 5,6 return putFullDoc(jio, "third_doc", docs[2], "data", blobs[2]); // 5,6
}) })
.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 () { .push(function () {
return jio.allDocs({ return jio.allDocs({
query: "NOT (date: > 2)", query: "NOT (date: > 2)",
...@@ -1641,20 +1712,20 @@ ...@@ -1641,20 +1712,20 @@
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {date: 1}, //timestamp: timestamps[2],
timestamp: timestamps[2] value: {date: 1}
}, },
{ {
doc: {}, doc: {},
id: "third_doc", id: "third_doc",
value: {date: 2}, //timestamp: timestamps[6],
timestamp: timestamps[6] value: {date: 2}
}, },
{ {
doc: {}, doc: {},
id: "second_doc", id: "second_doc",
value: {date: 2}, //timestamp: timestamps[4],
timestamp: timestamps[4] value: {date: 2}
} }
], ],
"Query gives correct results in correct order"); "Query gives correct results in correct order");
...@@ -1881,63 +1952,63 @@ ...@@ -1881,63 +1952,63 @@
{ {
doc: {}, doc: {},
id: "second_doc", id: "second_doc",
//timestamp: timestamps[9],
value: { value: {
date: 4, date: 4,
title: "second_doc", title: "second_doc",
type: "bar2" type: "bar2"
}, }
timestamp: timestamps[9]
}, },
{ {
doc: {}, doc: {},
id: "second_doc", id: "second_doc",
//timestamp: timestamps[8],
value: { value: {
date: 4, date: 4,
title: "second_doc", title: "second_doc",
type: "bar2" type: "bar2"
}, }
timestamp: timestamps[8]
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
//timestamp: timestamps[6],
value: { value: {
date: 4, date: 4,
title: "doc", title: "doc",
type: "foo2" type: "foo2"
}, }
timestamp: timestamps[6]
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
//timestamp: timestamps[5],
value: { value: {
date: 4, date: 4,
title: "doc", title: "doc",
type: "foo2" type: "foo2"
}, }
timestamp: timestamps[5]
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
//timestamp: timestamps[2],
value: { value: {
date: 1, date: 1,
title: "doc", title: "doc",
type: "foo" type: "foo"
}, }
timestamp: timestamps[2]
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
//timestamp: timestamps[1],
value: { value: {
date: 1, date: 1,
title: "doc", title: "doc",
type: "foo" type: "foo"
}, }
timestamp: timestamps[1]
} }
], ],
"Query gives correct results in correct order"); "Query gives correct results in correct order");
...@@ -1957,7 +2028,6 @@ ...@@ -1957,7 +2028,6 @@
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history, not_history = this.not_history,
timestamps,
blob = new Blob(['a']); blob = new Blob(['a']);
jio.put("document", {title: "foo"}) jio.put("document", {title: "foo"})
...@@ -1967,18 +2037,6 @@ ...@@ -1967,18 +2037,6 @@
.push(function () { .push(function () {
return jio.putAttachment("document", "attachment", blob); return jio.putAttachment("document", "attachment", blob);
}) })
// Get timestamps
.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 () { .push(function () {
return history.allDocs({select_list: ["title"]}); return history.allDocs({select_list: ["title"]});
}) })
...@@ -1987,20 +2045,20 @@ ...@@ -1987,20 +2045,20 @@
{ {
id: "document", id: "document",
doc: {}, doc: {},
value: {}, //timestamp: timestamps[2],
timestamp: timestamps[2] value: {}
}, },
{ {
id: "document", id: "document",
doc: {}, doc: {},
value: {}, //timestamp: timestamps[1],
timestamp: timestamps[1] value: {}
}, },
{ {
id: "document", id: "document",
doc: {}, doc: {},
value: {title: "foo"}, //timestamp: timestamps[0],
timestamp: timestamps[0] value: {title: "foo"}
}], }],
"Attachment on removed document is handled correctly" "Attachment on removed document is handled correctly"
); );
...@@ -2021,8 +2079,6 @@ ...@@ -2021,8 +2079,6 @@
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history,
timestamps,
blob = new Blob(['a']); blob = new Blob(['a']);
jio.put("document", {title: "foo"}) jio.put("document", {title: "foo"})
...@@ -2033,18 +2089,6 @@ ...@@ -2033,18 +2089,6 @@
return jio.removeAttachment("document", "attachment"); return jio.removeAttachment("document", "attachment");
}) })
// Get timestamps
.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 () { .push(function () {
return history.allDocs({select_list: ["title"]}); return history.allDocs({select_list: ["title"]});
}) })
...@@ -2053,20 +2097,20 @@ ...@@ -2053,20 +2097,20 @@
{ {
id: "document", id: "document",
doc: {}, doc: {},
value: {title: "foo"}, //timestamp: timestamps[2],
timestamp: timestamps[2] value: {title: "foo"}
}, },
{ {
id: "document", id: "document",
doc: {}, doc: {},
value: {title: "foo"}, //timestamp: timestamps[1],
timestamp: timestamps[1] value: {title: "foo"}
}, },
{ {
id: "document", id: "document",
doc: {}, doc: {},
value: {title: "foo"}, //timestamp: timestamps[0],
timestamp: timestamps[0] value: {title: "foo"}
}], }],
"Attachment on removed document is handled correctly" "Attachment on removed document is handled correctly"
); );
...@@ -2133,6 +2177,48 @@ ...@@ -2133,6 +2177,48 @@
.always(function () {start(); }); .always(function () {start(); });
}); });
test("Adding second query storage on top of history",
function () {
stop();
expect(1);
var jio = this.jio;
return jio.put("doca", {title: "foo0", date: 0})
.push(function () {
return jio.put("docb", {title: "bar0", date: 0});
})
.push(function () {
return jio.put("docb", {title: "bar1", date: 0});
})
.push(function () {
return jio.put("doca", {title: "foo1", date: 1});
})
.push(function () {
return jio.put("docb", {title: "bar2", date: 2});
})
.push(function () {
return jio.allDocs({
query: "title: foo1 OR title: bar2",
select_list: ["title"],
sort_on: [["date", "ascending"]],
limit: [0, 1]
});
})
.push(function (results) {
deepEqual(results.data.rows, [
{
doc: {},
id: "doca",
value: {title: "foo1"}
}
]);
})
.fail(function (error) {
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
});
module("HistoryStorage.Full-Example", { module("HistoryStorage.Full-Example", {
setup: function () { setup: function () {
...@@ -2144,28 +2230,34 @@ ...@@ -2144,28 +2230,34 @@
this.other_blob = new Blob(['1']); this.other_blob = new Blob(['1']);
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "history", type: "query",
sub_storage: { sub_storage: {
type: "query", type: "history",
sub_storage: { sub_storage: {
type: "uuid", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "uuid",
database: dbname sub_storage: {
type: "indexeddb",
database: dbname
}
} }
} }
} }
}); });
this.history = jIO.createJIO({ this.history = jIO.createJIO({
type: "history", type: "query",
include_revisions: true,
sub_storage: { sub_storage: {
type: "query", type: "history",
include_revisions: true,
sub_storage: { sub_storage: {
type: "uuid", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "uuid",
database: dbname sub_storage: {
type: "indexeddb",
database: dbname
}
} }
} }
} }
...@@ -2189,8 +2281,6 @@ ...@@ -2189,8 +2281,6 @@
expect(1); expect(1);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history,
timestamps,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
new Blob(['ab']), new Blob(['ab']),
...@@ -2225,18 +2315,6 @@ ...@@ -2225,18 +2315,6 @@
return putFullDoc(jio, "doc", {title: "bar3"}, "data", blobs1[4]); return putFullDoc(jio, "doc", {title: "bar3"}, "data", blobs1[4]);
}) })
// Get timestamps
.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 () { .push(function () {
return history.allDocs({ return history.allDocs({
select_list: ["title"] select_list: ["title"]
...@@ -2247,86 +2325,86 @@ ...@@ -2247,86 +2325,86 @@
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar3"}, //timestamp: timestamps[13],
timestamp: timestamps[13] value: {title: "bar3"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar3"}, //timestamp: timestamps[12],
timestamp: timestamps[12] value: {title: "bar3"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar2"}, //timestamp: timestamps[11],
timestamp: timestamps[11] value: {title: "bar2"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar2"}, //timestamp: timestamps[10],
timestamp: timestamps[10] value: {title: "bar2"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: "doc2",
value: {title: "foo1"}, //timestamp: timestamps[9],
timestamp: timestamps[9] value: {title: "foo1"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: "doc2",
value: {title: "foo1"}, //timestamp: timestamps[8],
timestamp: timestamps[8] value: {title: "foo1"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: "doc2",
value: {title: "foo0"}, //timestamp: timestamps[7],
timestamp: timestamps[7] value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: "doc2",
value: {title: "foo0"}, //timestamp: timestamps[6],
timestamp: timestamps[6] value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar1"}, //timestamp: timestamps[5],
timestamp: timestamps[5] value: {title: "bar1"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar1"}, //timestamp: timestamps[4],
timestamp: timestamps[4] value: {title: "bar1"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[3],
timestamp: timestamps[3] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[2],
timestamp: timestamps[2] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar"}, //timestamp: timestamps[1],
timestamp: timestamps[1] value: {title: "bar"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar"}, //timestamp: timestamps[0],
timestamp: timestamps[0] value: {title: "bar"}
} }
], ],
"allDocs with include_revisions should return all revisions"); "allDocs with include_revisions should return all revisions");
...@@ -2344,9 +2422,7 @@ ...@@ -2344,9 +2422,7 @@
stop(); stop();
expect(1); expect(1);
var jio = this.jio, var jio = this.jio,
not_history = this.not_history,
history = this.history, history = this.history,
timestamps,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
new Blob(['ab']), new Blob(['ab']),
...@@ -2368,18 +2444,6 @@ ...@@ -2368,18 +2444,6 @@
return jio.putAttachment("doc", "data", blobs1[1]); return jio.putAttachment("doc", "data", blobs1[1]);
}) })
// Get timestamps
.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 () { .push(function () {
return history.allDocs({ return history.allDocs({
select_list: ["title"] select_list: ["title"]
...@@ -2390,32 +2454,32 @@ ...@@ -2390,32 +2454,32 @@
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[4],
timestamp: timestamps[4] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: "doc2",
value: {title: "foo0"}, //timestamp: timestamps[3],
timestamp: timestamps[3] value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[2],
timestamp: timestamps[2] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[1],
timestamp: timestamps[1] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar"}, //timestamp: timestamps[0],
timestamp: timestamps[0] value: {title: "bar"}
} }
], ],
"allDocs with include_revisions should return all revisions"); "allDocs with include_revisions should return all revisions");
...@@ -2433,9 +2497,7 @@ ...@@ -2433,9 +2497,7 @@
stop(); stop();
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
not_history = this.not_history,
history = this.history, history = this.history,
timestamps,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
new Blob(['ab']), new Blob(['ab']),
...@@ -2456,18 +2518,6 @@ ...@@ -2456,18 +2518,6 @@
.push(function () { .push(function () {
return jio.putAttachment("doc", "data", blobs1[1]); return jio.putAttachment("doc", "data", blobs1[1]);
}) })
// Get timestamps
.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 () { .push(function () {
return jio.allDocs({ return jio.allDocs({
select_list: ["title"] select_list: ["title"]
...@@ -2478,14 +2528,14 @@ ...@@ -2478,14 +2528,14 @@
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[4],
timestamp: timestamps[4] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: "doc2",
value: {title: "foo0"}, //timestamp: timestamps[3],
timestamp: timestamps[3] value: {title: "foo0"}
} }
], ],
"allDocs with include_revisions false should return all revisions"); "allDocs with include_revisions false should return all revisions");
...@@ -2500,32 +2550,32 @@ ...@@ -2500,32 +2550,32 @@
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[4],
timestamp: timestamps[4] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: "doc2",
value: {title: "foo0"}, //timestamp: timestamps[3],
timestamp: timestamps[3] value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[2],
timestamp: timestamps[2] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar0"}, //timestamp: timestamps[1],
timestamp: timestamps[1] value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: "doc",
value: {title: "bar"}, //timestamp: timestamps[0],
timestamp: timestamps[0] value: {title: "bar"}
} }
], ],
"allDocs with include_revisions true should return all revisions"); "allDocs with include_revisions true should return all revisions");
......
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