diff --git a/CHANGELOG b/CHANGELOG index 2b2d1a0e6d..b4bcfc6d07 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ v3.5.1 (XXXX-XX-XX) ------------------- +* The graph viewer of the web interface now tries to find a vertex document of + all available vertex collections before it aborts. + * Fixed issue #9795: fix AQL `NOT IN` clause in SEARCH operations for ArangoSearch views. diff --git a/js/apps/system/_admin/aardvark/APP/aardvark.js b/js/apps/system/_admin/aardvark/APP/aardvark.js index c448243d0f..017f8a8c51 100644 --- a/js/apps/system/_admin/aardvark/APP/aardvark.js +++ b/js/apps/system/_admin/aardvark/APP/aardvark.js @@ -568,14 +568,9 @@ authRouter.get('/graph/:name', function (req, res) { if (!verticesCollections || verticesCollections.length === 0) { res.throw('bad request', 'no vertex collections found for graph'); } - var vertexName; - try { - vertexName = verticesCollections[Math.floor(Math.random() * verticesCollections.length)].name(); - } catch (err) { - res.throw('bad request', 'vertex collection of graph not found'); - } var vertexCollections = []; + _.each(graph._vertexCollections(), function (vertex) { vertexCollections.push({ name: vertex.name(), @@ -583,7 +578,6 @@ authRouter.get('/graph/:name', function (req, res) { }); }); - var startVertex; var config; try { @@ -592,25 +586,40 @@ authRouter.get('/graph/:name', function (req, res) { res.throw('bad request', e.message, {cause: e}); } - var getPseudoRandomStartVertex = function (collName) { - let maxDoc = db[collName].count(); - if (maxDoc === 0) { - return null; - } - if (maxDoc > 1000) { - maxDoc = 1000; - } - let randDoc = Math.floor(Math.random() * maxDoc); + var getPseudoRandomStartVertex = function () { + for (var i = 0; i < graph._vertexCollections().length; i++) { + var vertexCollection = graph._vertexCollections()[i]; + let maxDoc = db[vertexCollection.name()].count(); - return db._query( - 'FOR vertex IN @@vertexCollection LIMIT @skipN, 1 RETURN vertex', - { - '@vertexCollection': collName, - 'skipN': randDoc + if (maxDoc === 0) { + continue; } - ).toArray()[0]; + + if (maxDoc > 1000) { + maxDoc = 1000; + } + + let randDoc = Math.floor(Math.random() * maxDoc); + + let potentialVertex = db._query( + 'FOR vertex IN @@vertexCollection LIMIT @skipN, 1 RETURN vertex', + { + '@vertexCollection': vertexCollection.name(), + 'skipN': randDoc + } + ).toArray()[0]; + + if (potentialVertex) { + return potentialVertex; + } + } + + return null; }; + var multipleIds; + var startVertex; // will be "randomly" choosen if no start vertex is specified + if (config.nodeStart) { if (config.nodeStart.indexOf(' ') > -1) { multipleIds = config.nodeStart.split(' '); @@ -621,11 +630,11 @@ authRouter.get('/graph/:name', function (req, res) { res.throw('bad request', e.message, {cause: e}); } if (!startVertex) { - startVertex = getPseudoRandomStartVertex(vertexName); + startVertex = getPseudoRandomStartVertex(); } } } else { - startVertex = getPseudoRandomStartVertex(vertexName); + startVertex = getPseudoRandomStartVertex(); } var limit = 0; @@ -639,7 +648,7 @@ authRouter.get('/graph/:name', function (req, res) { if (startVertex === null) { toReturn = { empty: true, - msg: 'Your graph is empty', + msg: 'Your graph is empty. We did not find a document in any available vertex collection.', settings: { vertexCollections: vertexCollections }