1
0
Fork 0

Bug fix 3.5/ui optimize graph load (#9832)

* iterate through all vertexCollections of a graph to find a vertex to display

* changelog
This commit is contained in:
Heiko 2019-08-29 12:07:57 +02:00 committed by KVS85
parent 1eef617a07
commit d9507f8134
2 changed files with 37 additions and 25 deletions

View File

@ -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.

View File

@ -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
}