mirror of https://gitee.com/bigwinds/arangodb
Minor perfromance improvements for graph traversals
This commit is contained in:
parent
c79969f40f
commit
2bb36889b2
|
@ -319,32 +319,54 @@ function outboundExpander (config, vertex, path) {
|
||||||
var datasource = config.datasource;
|
var datasource = config.datasource;
|
||||||
var connections = [ ];
|
var connections = [ ];
|
||||||
var outEdges = datasource.getOutEdges(vertex);
|
var outEdges = datasource.getOutEdges(vertex);
|
||||||
|
var edgeIterator;
|
||||||
|
|
||||||
if (outEdges.length > 1 && config.sort) {
|
if (outEdges.length > 1 && config.sort) {
|
||||||
outEdges.sort(config.sort);
|
outEdges.sort(config.sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
outEdges.forEach(function (edge) {
|
|
||||||
try {
|
|
||||||
var v;
|
|
||||||
if (config.buildVertices) {
|
if (config.buildVertices) {
|
||||||
v = datasource.getInVertex(edge);
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getInVertex(edge);
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
// optimization to save vertex lookups
|
// continue even in the face of non-existing documents
|
||||||
v = { _id: datasource.getEdgeTo(edge) };
|
|
||||||
v._key = v._id.split("/")[1];
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if (! config.expandFilter || config.expandFilter(config, v, edge, path)) {
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getInVertex(edge);
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
connections.push({ edge: edge, vertex: v });
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// continue even in the face of non-existing documents
|
// continue even in the face of non-existing documents
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeTo(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeTo(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outEdges.forEach(edgeIterator);
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,27 +383,50 @@ function inboundExpander (config, vertex, path) {
|
||||||
if (inEdges.length > 1 && config.sort) {
|
if (inEdges.length > 1 && config.sort) {
|
||||||
inEdges.sort(config.sort);
|
inEdges.sort(config.sort);
|
||||||
}
|
}
|
||||||
|
var edgeIterator;
|
||||||
|
|
||||||
inEdges.forEach(function (edge) {
|
|
||||||
try {
|
|
||||||
var v;
|
|
||||||
if (config.buildVertices) {
|
if (config.buildVertices) {
|
||||||
v = datasource.getOutVertex(edge);
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getOutVertex(edge);
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
// optimization to save vertex lookups
|
// continue even in the face of non-existing documents
|
||||||
v = { _id: datasource.getEdgeFrom(edge) };
|
|
||||||
v._key = v._id.split("/")[1];
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if (! config.expandFilter || config.expandFilter(config, v, edge, path)) {
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getOutVertex(edge);
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
connections.push({ edge: edge, vertex: v });
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// continue even in the face of non-existing documents
|
// continue even in the face of non-existing documents
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inEdges.forEach(edgeIterator);
|
||||||
|
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
@ -399,34 +444,55 @@ function anyExpander (config, vertex, path) {
|
||||||
edges.sort(config.sort);
|
edges.sort(config.sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
edges.forEach(function (edge) {
|
var edgeIterator;
|
||||||
try {
|
|
||||||
var v;
|
|
||||||
if (config.buildVertices) {
|
if (config.buildVertices) {
|
||||||
v = datasource.getPeerVertex(edge, vertex);
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getPeerVertex(edge);
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
// optimization to save vertex lookups
|
// continue even in the face of non-existing documents
|
||||||
v = { };
|
|
||||||
if (datasource.getEdgeFrom(edge) === vertex._id) {
|
|
||||||
v._id = datasource.getEdgeTo(edge);
|
|
||||||
v._key = v._id.split("/")[1];
|
|
||||||
}
|
}
|
||||||
else if (datasource.getEdgeTo(edge) === vertex._id) {
|
};
|
||||||
v._id = datasource.getEdgeFrom(edge);
|
} else {
|
||||||
v._key = v._id.split("/")[1];
|
edgeIterator = function(edge) {
|
||||||
}
|
try {
|
||||||
}
|
var v = datasource.getPeerVertex(edge);
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
if (! config.expandFilter || config.expandFilter(config, v, edge, path)) {
|
|
||||||
connections.push({ edge: edge, vertex: v });
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// continue even in the face of non-existing documents
|
// continue even in the face of non-existing documents
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
if (id === vertex._id) {
|
||||||
|
id = datasource.getEdgeTo(edge);
|
||||||
|
}
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
if (id === vertex._id) {
|
||||||
|
id = datasource.getEdgeTo(edge);
|
||||||
|
}
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
edges.forEach(edgeIterator);
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1307,7 +1373,7 @@ ArangoTraverser = function (config) {
|
||||||
filter: null,
|
filter: null,
|
||||||
expander: outboundExpander,
|
expander: outboundExpander,
|
||||||
datasource: null,
|
datasource: null,
|
||||||
maxIterations: 1000000,
|
maxIterations: 10000000,
|
||||||
minDepth: 0,
|
minDepth: 0,
|
||||||
maxDepth: 256,
|
maxDepth: 256,
|
||||||
buildVertices: true
|
buildVertices: true
|
||||||
|
|
|
@ -318,32 +318,54 @@ function outboundExpander (config, vertex, path) {
|
||||||
var datasource = config.datasource;
|
var datasource = config.datasource;
|
||||||
var connections = [ ];
|
var connections = [ ];
|
||||||
var outEdges = datasource.getOutEdges(vertex);
|
var outEdges = datasource.getOutEdges(vertex);
|
||||||
|
var edgeIterator;
|
||||||
|
|
||||||
if (outEdges.length > 1 && config.sort) {
|
if (outEdges.length > 1 && config.sort) {
|
||||||
outEdges.sort(config.sort);
|
outEdges.sort(config.sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
outEdges.forEach(function (edge) {
|
|
||||||
try {
|
|
||||||
var v;
|
|
||||||
if (config.buildVertices) {
|
if (config.buildVertices) {
|
||||||
v = datasource.getInVertex(edge);
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getInVertex(edge);
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
// optimization to save vertex lookups
|
// continue even in the face of non-existing documents
|
||||||
v = { _id: datasource.getEdgeTo(edge) };
|
|
||||||
v._key = v._id.split("/")[1];
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if (! config.expandFilter || config.expandFilter(config, v, edge, path)) {
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getInVertex(edge);
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
connections.push({ edge: edge, vertex: v });
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// continue even in the face of non-existing documents
|
// continue even in the face of non-existing documents
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeTo(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeTo(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outEdges.forEach(edgeIterator);
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,27 +382,50 @@ function inboundExpander (config, vertex, path) {
|
||||||
if (inEdges.length > 1 && config.sort) {
|
if (inEdges.length > 1 && config.sort) {
|
||||||
inEdges.sort(config.sort);
|
inEdges.sort(config.sort);
|
||||||
}
|
}
|
||||||
|
var edgeIterator;
|
||||||
|
|
||||||
inEdges.forEach(function (edge) {
|
|
||||||
try {
|
|
||||||
var v;
|
|
||||||
if (config.buildVertices) {
|
if (config.buildVertices) {
|
||||||
v = datasource.getOutVertex(edge);
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getOutVertex(edge);
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
// optimization to save vertex lookups
|
// continue even in the face of non-existing documents
|
||||||
v = { _id: datasource.getEdgeFrom(edge) };
|
|
||||||
v._key = v._id.split("/")[1];
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if (! config.expandFilter || config.expandFilter(config, v, edge, path)) {
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getOutVertex(edge);
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
connections.push({ edge: edge, vertex: v });
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// continue even in the face of non-existing documents
|
// continue even in the face of non-existing documents
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inEdges.forEach(edgeIterator);
|
||||||
|
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
@ -398,34 +443,55 @@ function anyExpander (config, vertex, path) {
|
||||||
edges.sort(config.sort);
|
edges.sort(config.sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
edges.forEach(function (edge) {
|
var edgeIterator;
|
||||||
try {
|
|
||||||
var v;
|
|
||||||
if (config.buildVertices) {
|
if (config.buildVertices) {
|
||||||
v = datasource.getPeerVertex(edge, vertex);
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
try {
|
||||||
|
var v = datasource.getPeerVertex(edge, vertex);
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
// optimization to save vertex lookups
|
// continue even in the face of non-existing documents
|
||||||
v = { };
|
|
||||||
if (datasource.getEdgeFrom(edge) === vertex._id) {
|
|
||||||
v._id = datasource.getEdgeTo(edge);
|
|
||||||
v._key = v._id.split("/")[1];
|
|
||||||
}
|
}
|
||||||
else if (datasource.getEdgeTo(edge) === vertex._id) {
|
};
|
||||||
v._id = datasource.getEdgeFrom(edge);
|
} else {
|
||||||
v._key = v._id.split("/")[1];
|
edgeIterator = function(edge) {
|
||||||
}
|
try {
|
||||||
}
|
var v = datasource.getPeerVertex(edge, vertex);
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
if (! config.expandFilter || config.expandFilter(config, v, edge, path)) {
|
|
||||||
connections.push({ edge: edge, vertex: v });
|
connections.push({ edge: edge, vertex: v });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// continue even in the face of non-existing documents
|
// continue even in the face of non-existing documents
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!config.expandFilter) {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
if (id === vertex._id) {
|
||||||
|
id = datasource.getEdgeTo(edge);
|
||||||
|
}
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
edgeIterator = function(edge) {
|
||||||
|
var id = datasource.getEdgeFrom(edge);
|
||||||
|
if (id === vertex._id) {
|
||||||
|
id = datasource.getEdgeTo(edge);
|
||||||
|
}
|
||||||
|
var v = { _id: id, _key: id.substr(id.indexOf("/") + 1)};
|
||||||
|
if (config.expandFilter(config, v, edge, path)) {
|
||||||
|
connections.push({ edge: edge, vertex: v });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
edges.forEach(edgeIterator);
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1306,7 +1372,7 @@ ArangoTraverser = function (config) {
|
||||||
filter: null,
|
filter: null,
|
||||||
expander: outboundExpander,
|
expander: outboundExpander,
|
||||||
datasource: null,
|
datasource: null,
|
||||||
maxIterations: 1000000,
|
maxIterations: 10000000,
|
||||||
minDepth: 0,
|
minDepth: 0,
|
||||||
maxDepth: 256,
|
maxDepth: 256,
|
||||||
buildVertices: true
|
buildVertices: true
|
||||||
|
|
Loading…
Reference in New Issue