Commit db110599 authored by Tristan Cavelier's avatar Tristan Cavelier

revisionstorage.js private methods improved

parent 670fa773
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* } * }
*/ */
jIO.addStorageType('revision', function (spec, my) { jIO.addStorageType('revision', function (spec, my) {
"use strict";
var that, priv = {}; var that, priv = {};
spec = spec || {}; spec = spec || {};
that = my.basicStorage(spec, my); that = my.basicStorage(spec, my);
...@@ -155,7 +156,9 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -155,7 +156,9 @@ jIO.addStorageType('revision', function (spec, my) {
* @return {array} The added document revs_info * @return {array} The added document revs_info
*/ */
priv.postToDocumentTree = function (doctree, doc) { priv.postToDocumentTree = function (doctree, doc) {
var revs_info = [], next_rev, selectNode, selected_node = doctree; var i, revs_info, next_rev, next_rev_str, selectNode, selected_node;
revs_info = [];
selected_node = doctree;
selectNode = function (node) { selectNode = function (node) {
var i; var i;
if (typeof node.rev !== "undefined") { if (typeof node.rev !== "undefined") {
...@@ -192,11 +195,27 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -192,11 +195,27 @@ jIO.addStorageType('revision', function (spec, my) {
} }
next_rev = priv.generateNextRevision( next_rev = priv.generateNextRevision(
doc._rev || 0, JSON.stringify(doc) + JSON.stringify(revs_info)); doc._rev || 0, JSON.stringify(doc) + JSON.stringify(revs_info));
next_rev_str = next_rev.join("-");
// don't add if the next rev already exists
console.log (JSON.stringify (revs_info));
for (i = 0; i < selected_node.children.length; i += 1) {
console.log (selected_node.children[i].rev);
if (selected_node.children[i].rev === next_rev_str) {
revs_info.unshift({
"rev": next_rev_str,
"status": "available"
});
if (selected_node.children[i].status !== "available") {
selected_node.children[i].status = "available";
}
return revs_info;
}
}
revs_info.unshift({ revs_info.unshift({
"rev": next_rev.join('-'), "rev": next_rev.join('-'),
"status": "available" "status": "available"
}); });
selected_node.children.push({ selected_node.children.unshift({
"rev": next_rev.join('-'), "rev": next_rev.join('-'),
"status": "available", "status": "available",
"children": [] "children": []
......
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