diff --git a/js/common/modules/org/arangodb/general-graph.js b/js/common/modules/org/arangodb/general-graph.js index bc08653ea7..b8b27cdad4 100644 --- a/js/common/modules/org/arangodb/general-graph.js +++ b/js/common/modules/org/arangodb/general-graph.js @@ -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); + */ }; diff --git a/js/common/tests/shell-general-graph.js b/js/common/tests/shell-general-graph.js index 2370f18029..e8545ce584 100644 --- a/js/common/tests/shell-general-graph.js +++ b/js/common/tests/shell-general-graph.js @@ -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);