1
0
Fork 0

Fixed a minor bug when updating the edge definitions. The currently referenced graph object was not updated properly, the stored one was.

This commit is contained in:
Michael Hackstein 2014-07-08 15:23:59 +02:00
parent 4cf8df05dc
commit bbda062747
2 changed files with 47 additions and 30 deletions

View File

@ -3864,7 +3864,6 @@ Graph.prototype._extendEdgeDefinitions = function(edgeDefinition) {
var changeEdgeDefinitionsForGraph = function(graph, edgeDefinition, newCollections, possibleOrphans, self) {
var oldCollections = [];
var graphCollections = [];
var graphObj = _graph(graph._key);
var eDs = graph.edgeDefinitions;
@ -3875,8 +3874,6 @@ var changeEdgeDefinitionsForGraph = function(graph, edgeDefinition, newCollectio
function(eD, id) {
if(eD.collection === edgeDefinition.collection) {
gotAHit = true;
oldCollections = _.union(oldCollections, eD.from);
oldCollections = _.union(oldCollections, eD.to);
eDs[id].from = edgeDefinition.from;
eDs[id].to = edgeDefinition.to;
db._graphs.update(graph._key, {edgeDefinitions: eDs});
@ -3891,32 +3888,50 @@ var changeEdgeDefinitionsForGraph = function(graph, edgeDefinition, newCollectio
}
}
);
if (!gotAHit) {
return;
}
//remove used collection from orphanage
newCollections.forEach(
function(nc) {
if (graph._key === self.__name) {
if (graph._key === self.__name) {
newCollections.forEach(
function(nc) {
if (self.__vertexCollections[nc] === undefined) {
self.__vertexCollections[nc] = db[nc];
}
try {
graphObj._removeVertexCollection(nc, false);
} catch (ignore) {
self._removeVertexCollection(nc, false);
} catch (ignore) { }
}
);
possibleOrphans.forEach(
function(po) {
if (graphCollections.indexOf(po) === -1) {
delete self.__vertexCollections[po];
self._addVertexCollection(po);
}
}
}
);
);
} else {
newCollections.forEach(
function(nc) {
try {
graphObj._removeVertexCollection(nc, false);
} catch (ignore) { }
}
);
possibleOrphans.forEach(
function(po) {
if (graphCollections.indexOf(po) === -1) {
delete graphObj.__vertexCollections[po];
graphObj._addVertexCollection(po);
}
}
);
}
//move unused collections to orphanage
possibleOrphans.forEach(
function(po) {
if (graphCollections.indexOf(po) === -1 && gotAHit) {
delete graphObj.__vertexCollections[po];
graphObj._addVertexCollection(po);
}
}
);
};
////////////////////////////////////////////////////////////////////////////////
@ -3952,6 +3967,11 @@ var changeEdgeDefinitionsForGraph = function(graph, edgeDefinition, newCollectio
///
////////////////////////////////////////////////////////////////////////////////
Graph.prototype._editEdgeDefinitions = function(edgeDefinition) {
/*
require("internal").print("Before:");
require("internal").print(this.__vertexCollections);
require("internal").print(this.__orphanCollections);
*/
edgeDefinition = sortEdgeDefinition(edgeDefinition);
var self = this;
@ -3993,6 +4013,11 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition) {
}
);
updateBindCollections(this);
/*
require("internal").print("After:");
require("internal").print(this.__vertexCollections);
require("internal").print(this.__orphanCollections);
*/
};

View File

@ -635,14 +635,9 @@ function GeneralGraphCreationSuite() {
g1._editEdgeDefinitions(dr3);
assertEqual([dr3, dr2], g1.__edgeDefinitions);
assertEqual([dr3], g2.__edgeDefinitions);
g1 = graph._graph(gN1);
g2 = graph._graph(gN2);
assertTrue(g1._orphanCollections().indexOf(vc2) !== -1);
assertTrue(g1._orphanCollections().indexOf(vc3) !== -1);
assertTrue(g2._orphanCollections().indexOf(vc1) !== -1);
assertTrue(g2._orphanCollections().indexOf(vc2) !== -1);
assertTrue(g2._orphanCollections().indexOf(vc3) !== -1);
assertTrue(g2._orphanCollections().indexOf(vc4) !== -1);
assertEqual(g1._orphanCollections().sort(), [vc2, vc3].sort());
assertEqual(g2._orphanCollections().sort(), [vc1, vc2, vc3, vc4].sort());
},
@ -661,12 +656,9 @@ function GeneralGraphCreationSuite() {
assertEqual([dr2, dr3], g1.__edgeDefinitions);
assertEqual([dr2], g2.__edgeDefinitions);
g1 = graph._graph(gN1);
g2 = graph._graph(gN2);
assertEqual([vc1], g1._orphanCollections());
assertTrue(g2._orphanCollections().indexOf(vc1) !== -1);
assertTrue(g2._orphanCollections().indexOf(vc2) !== -1);
assertTrue(g2._orphanCollections().indexOf(vc6) !== -1);
assertEqual(g2._orphanCollections().sort(), [vc1, vc2, vc6].sort());
try {
graph._drop(gN1, true);