Commit b3ae0524 authored by Tristan Cavelier's avatar Tristan Cavelier

revisionstorage.js get method updated

parent 04bd89df
...@@ -433,12 +433,8 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -433,12 +433,8 @@ jIO.addStorageType('revision', function (spec, my) {
); );
}; };
f.postDocument = function (doctree_update_method) { f.postDocument = function (doctree_update_method) {
revs_info = priv.postToDocumentTree(doctree, doc, revs_info = priv.postToDocumentTree(doctree, doc);
priv.update_doctree_on_remove);
// I don't understand why?
doc._id = docid+"."+revs_info[0].rev; doc._id = docid+"."+revs_info[0].rev;
that.addJob( that.addJob(
"post", "post",
priv.substorage, priv.substorage,
...@@ -511,7 +507,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -511,7 +507,7 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.get = function (command) { that.get = function (command) {
var f = {}, doctree, revs_info, prev_rev, rev_path, option; var f = {}, doctree, revs_info, prev_rev, option;
option = command.cloneOption(); option = command.cloneOption();
if (option["max_retry"] === 0) { if (option["max_retry"] === 0) {
option["max_retry"] = 3; option["max_retry"] = 3;
...@@ -538,11 +534,16 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -538,11 +534,16 @@ jIO.addStorageType('revision', function (spec, my) {
option, option,
function (response) { function (response) {
doctree = response; doctree = response;
revs_info = priv.getWinnerRevisionFromDocumentTree(doctree);
if (prev_rev === undefined) { if (prev_rev === undefined) {
revs_info =
priv.getWinnerRevisionFromDocumentTree(doctree);
prev_rev = revs_info[0].rev; prev_rev = revs_info[0].rev;
} else {
revs_info =
priv.getRevisionFromDocumentTree(doctree, prev_rev);
} }
f.getDocument(command.getDocId()+"."+prev_rev); f.getDocument(command.getDocId()+"."+prev_rev,
command.getAttachmentId());
}, function (err) { }, function (err) {
switch(err.status) { switch(err.status) {
case 404: case 404:
...@@ -556,14 +557,36 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -556,14 +557,36 @@ jIO.addStorageType('revision', function (spec, my) {
} }
); );
}; };
f.getDocument = function (docid) { f.getDocument = function (docid, attmtid) {
that.addJob( that.addJob(
"get", "get",
priv.substorage, priv.substorage,
docid, docid,
option, option,
function (response) { function (response) {
var attmt;
if (typeof response !== "string") { if (typeof response !== "string") {
if (attmtid !== undefined) {
if (response._attachments !== undefined) {
attmt = response._attachments[attmtid];
if (attmt !== undefined) {
prev_rev =
priv.getRevisionFromPosition(
revs_info, attmt.revpos);
f.getDocument(command.getDocId()+"."+
prev_rev+"/"+attmtid);
return;
}
}
that.error({
"status": 404,
"statusText": "Not Found",
"error": "not_found",
"message": "Cannot find the attachment",
"reason": "Attachment is missing"
});
return;
}
response._id = command.getDocId(); response._id = command.getDocId();
response._rev = prev_rev; response._rev = prev_rev;
if (command.getOption("revs") === true) { if (command.getOption("revs") === true) {
...@@ -588,36 +611,9 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -588,36 +611,9 @@ jIO.addStorageType('revision', function (spec, my) {
} }
); );
}; };
if (command.getAttachmentId()) { if (command.getAttachmentId() && prev_rev !== undefined) {
// xxx: no revision passed = get tree and winning revision f.getDocument(command.getDocId()+"."+prev_rev+
if ( prev_rev === undefined ){ "/"+command.getAttachmentId());
that.addJob(
"get",
priv.substorage,
command.getDocId()+priv.doctree_suffix,
option,
function (response) {
rev_path = "."+priv.getWinnerRevisionFromDocumentTree(
response)[0].rev;
f.getDocument(command.getDocId()+
rev_path+"/"+command.getAttachmentId());
},
function (err) {
that.error({
"status": 404,
"statusText": "Not Found",
"error": "not_found",
"message": "Document tree not found, please check document ID",
"reason": "Incorrect document ID"
});
return;
}
);
} else {
f.getDocument(command.getDocId()+"."+
prev_rev+"/"+command.getAttachmentId());
}
} else { } else {
f.getDocumentTree(); f.getDocumentTree();
} }
......
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