Commit 60eac4f9 authored by Tristan Cavelier's avatar Tristan Cavelier

jio get: "_rev" is required in the document, no longer in the options.

parent d41b35da
...@@ -305,20 +305,19 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -305,20 +305,19 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.get = function (command) { that.get = function (command) {
var functions = {}, doc_env, docid, my_rev, revs_array = []; var functions = {}, doc_env, doc, my_rev, revs_array = [];
functions.begin = function () { functions.begin = function () {
var i, option; var i;
docid = command.getDocId(); doc = command.cloneDoc();
doc_env = my.env[docid]; doc_env = my.env[doc._id];
if (!doc_env || !doc_env.id) { if (!doc_env || !doc_env.id) {
// document environment is not set // document environment is not set
doc_env = priv.initEnv(docid); doc_env = priv.initEnv(doc._id);
} }
// document environment is set now // document environment is set now
revs_array.length = priv.storage_list.length; revs_array.length = priv.storage_list.length;
option = command.cloneOption() || {}; my_rev = doc._rev;
my_rev = option.rev;
if (my_rev) { if (my_rev) {
functions.update_env = false; functions.update_env = false;
} }
...@@ -326,9 +325,9 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -326,9 +325,9 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
// request all sub storages // request all sub storages
if (doc_env.my_revisions[my_rev]) { if (doc_env.my_revisions[my_rev]) {
// if my_rev exist, convert it to distant revision // if my_rev exist, convert it to distant revision
option.rev = doc_env.my_revisions[my_rev][i]; doc._rev = doc_env.my_revisions[my_rev][i];
} }
priv.send("get", i, docid, priv.clone(option), functions.callback); priv.send("get", i, doc, command.cloneOption(), functions.callback);
} }
}; };
functions.update_env = true; functions.update_env = true;
...@@ -349,7 +348,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -349,7 +348,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
} else { } else {
// the document revision is unknown // the document revision is unknown
if (functions.update_env === true) { if (functions.update_env === true) {
my_rev = priv.generateNextRevision(0, docid); my_rev = priv.generateNextRevision(0, doc._id);
doc_env.my_revisions[my_rev] = revs_array; doc_env.my_revisions[my_rev] = revs_array;
doc_env.distant_revisions[response._rev || "unique_" + index] = doc_env.distant_revisions[response._rev || "unique_" + index] =
my_rev; my_rev;
......
...@@ -923,7 +923,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -923,7 +923,7 @@ jIO.addStorageType('revision', function (spec, my) {
if (option.max_retry === 0) { if (option.max_retry === 0) {
option.max_retry = 3; option.max_retry = 3;
} }
prev_rev = command.getOption("rev"); prev_rev = command.getDocInfo("_rev");
if (typeof prev_rev === "string") { if (typeof prev_rev === "string") {
if (!priv.checkRevisionFormat(prev_rev)) { if (!priv.checkRevisionFormat(prev_rev)) {
that.error({ that.error({
...@@ -941,7 +941,8 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -941,7 +941,8 @@ jIO.addStorageType('revision', function (spec, my) {
that.addJob( that.addJob(
"get", "get",
priv.substorage, priv.substorage,
command.getDocId() + priv.doctree_suffix, {"_id": command.getDocId() + priv.doctree_suffix,
"_rev": command.getDocInfo("_rev")},
option, option,
function (response) { function (response) {
doctree = response; doctree = response;
...@@ -982,7 +983,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -982,7 +983,7 @@ jIO.addStorageType('revision', function (spec, my) {
that.addJob( that.addJob(
"get", "get",
priv.substorage, priv.substorage,
docid, {"_id": docid, "_rev": command.getDocInfo("_rev")},
option, option,
function (response) { function (response) {
var attmt; var attmt;
......
...@@ -1800,9 +1800,8 @@ test ("Get", function(){ ...@@ -1800,9 +1800,8 @@ test ("Get", function(){
// get inexistent specific document // get inexistent specific document
o.spy(o, "status", 404, "Get document (inexistent specific revision)"); o.spy(o, "status", 404, "Get document (inexistent specific revision)");
o.jio.get({"_id": "get1"}, { o.jio.get({"_id": "get1", "_rev": "1-rev0"}, {
"revs_info": true, "revs": true, "conflicts": true, "revs_info": true, "revs": true, "conflicts": true,
"rev": "1-rev0"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -1815,9 +1814,8 @@ test ("Get", function(){ ...@@ -1815,9 +1814,8 @@ test ("Get", function(){
}]; }];
o.doc_myget2_cloned["_conflicts"] = ["1-rev1"]; o.doc_myget2_cloned["_conflicts"] = ["1-rev1"];
o.spy(o, "value", o.doc_myget2_cloned, "Get document (specific revision)"); o.spy(o, "value", o.doc_myget2_cloned, "Get document (specific revision)");
o.jio.get({"_id": "get1"}, { o.jio.get({"_id": "get1", "_rev": "1-rev2"}, {
"revs_info": true, "revs": true, "conflicts": true, "revs_info": true, "revs": true, "conflicts": true,
"rev": "1-rev2"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -1842,17 +1840,15 @@ test ("Get", function(){ ...@@ -1842,17 +1840,15 @@ test ("Get", function(){
// get inexistent attachment specific rev // get inexistent attachment specific rev
o.spy(o, "status", 404, "Get inexistent attachment (specific revision)"); o.spy(o, "status", 404, "Get inexistent attachment (specific revision)");
o.jio.get({"_id": "get1/get2"}, { o.jio.get({"_id": "get1/get2", "_rev": "1-rev1"}, {
"revs_info": true, "revs": true, "conflicts": true, "revs_info": true, "revs": true, "conflicts": true,
"rev": "1-rev1"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
// get attachment specific rev // get attachment specific rev
o.spy(o, "value", "abc", "Get attachment (specific revision)"); o.spy(o, "value", "abc", "Get attachment (specific revision)");
o.jio.get({"_id": "get1/get2"}, { o.jio.get({"_id": "get1/get2", "_rev": "1-rev2"}, {
"revs_info": true, "revs": true, "conflicts": true, "revs_info": true, "revs": true, "conflicts": true,
"rev": "1-rev2"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -1860,9 +1856,8 @@ test ("Get", function(){ ...@@ -1860,9 +1856,8 @@ test ("Get", function(){
o.doc_myget2_cloned["_attachments"] = o.attmt_myget2; o.doc_myget2_cloned["_attachments"] = o.attmt_myget2;
o.spy(o, "value", o.doc_myget2_cloned, o.spy(o, "value", o.doc_myget2_cloned,
"Get document which have an attachment (specific revision)"); "Get document which have an attachment (specific revision)");
o.jio.get({"_id": "get1"}, { o.jio.get({"_id": "get1", "_rev": "1-rev2"}, {
"revs_info": true, "revs": true, "conflicts": true, "revs_info": true, "revs": true, "conflicts": true,
"rev": "1-rev2"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -2132,9 +2127,9 @@ test ("Scenario", function(){ ...@@ -2132,9 +2127,9 @@ test ("Scenario", function(){
o.doc._revs_info = [{"rev": o.rev, "status": "available"}]; o.doc._revs_info = [{"rev": o.rev, "status": "available"}];
o.spy(o, "value", o.doc, "And, on this new tab, I load the document,"+ o.spy(o, "value", o.doc, "And, on this new tab, I load the document,"+
"and my application keep the revision in memory"); "and my application keep the revision in memory");
o.jio2.get({"_id": "sample1"}, { o.jio2.get({"_id": "sample1", "_rev": o.rev}, {
"revs_info": true, "revs": true, "conflicts": true, "revs_info": true, "revs": true, "conflicts": true,
"rev": o.rev }, o.f); }, o.f);
o.tick(o); o.tick(o);
// MODFIY the 2nd version // MODFIY the 2nd version
...@@ -2431,11 +2426,10 @@ module ("JIO Replicate Revision Storage"); ...@@ -2431,11 +2426,10 @@ module ("JIO Replicate Revision Storage");
"_revs_info": [{"rev": "1-2", "status": "available"}], "_revs_info": [{"rev": "1-2", "status": "available"}],
"_conflicts": ["1-1"] "_conflicts": ["1-1"]
}, "Get the previous document (with revision)"); }, "Get the previous document (with revision)");
o.jio.get({"_id": "doc1"}, { o.jio.get({"_id": "doc1", "_rev": "1-2"}, {
"conflicts": true, "conflicts": true,
"revs": true, "revs": true,
"revs_info": true, "revs_info": true,
"rev": "1-2"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -2448,11 +2442,10 @@ module ("JIO Replicate Revision Storage"); ...@@ -2448,11 +2442,10 @@ module ("JIO Replicate Revision Storage");
"_revs_info": [{"rev": o.specific_rev, "status": "available"}], "_revs_info": [{"rev": o.specific_rev, "status": "available"}],
"_conflicts": [o.specific_rev_conflict] "_conflicts": [o.specific_rev_conflict]
}, "Get a previous document (with local storage revision)"); }, "Get a previous document (with local storage revision)");
o.jio.get({"_id": "doc1"}, { o.jio.get({"_id": "doc1", "_rev": o.specific_rev}, {
"conflicts": true, "conflicts": true,
"revs": true, "revs": true,
"revs_info": true, "revs_info": true,
"rev": o.specific_rev
}, o.f); }, o.f);
o.tick(o); o.tick(o);
......
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