Skip to content

Commit

Permalink
Update getEdgesDirections queries
Browse files Browse the repository at this point in the history
Replaces the queries to fetch edge directions while building the schema.
The old queries worked by testing for the existance of any possible edge,
which resulted in a large number of queries for graphs with lots of node and
edge labels.

The new query instead iterates through all the edge labels, and runs a query
to fetch the corresponding from-label to-label pairs.
  • Loading branch information
Cole-Greer committed Oct 11, 2024
1 parent f46acef commit 9c081e8
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/NeptuneSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,22 @@ async function getEdgesNames() {
}


async function checkEdgeDirection(direction) {
let query = `MATCH (from:${direction.from})-[r:${direction.edge.label}]->(to:${direction.to}) RETURN r as edge LIMIT 1`;
async function findFromAndToLabels(edgeStructure) {
let query = `MATCH (from)-[r:${edgeStructure.label}]->(to) RETURN DISTINCT labels(from) as fromLabel, labels(to) as toLabel`;
let response = await queryNeptune(query);
let result = response.results[0];
if (result !== undefined) {
direction.edge.directions.push({from:direction.from, to:direction.to});
consoleOut(' Found edge: ' + yellow(direction.edge.label) + ' direction: ' + yellow(direction.from) + ' -> ' + yellow(direction.to));
for (let result of response.results) {
for (let fromLabel of result.fromLabel) {
for (let toLabel of result.toLabel) {
edgeStructure.directions.push({from:fromLabel, to:toLabel});
consoleOut(' Found edge: ' + yellow(edgeStructure.label) + ' direction: ' + yellow(fromLabel) + ' -> ' + yellow(toLabel));
}
}
}
}


async function getEdgesDirections() {
let possibleDirections = [];
for (const edge of schema.edgeStructures) {
for (const fromNode of schema.nodeStructures) {
for (const toNode of schema.nodeStructures) {
possibleDirections.push({edge:edge, from:fromNode.label, to:toNode.label});
}
}
}

await Promise.all(possibleDirections.map(checkEdgeDirection))
await Promise.all(schema.edgeStructures.map(findFromAndToLabels))
}


Expand Down

0 comments on commit 9c081e8

Please sign in to comment.