Skip to content

Commit 9c081e8

Browse files
committed
Update getEdgesDirections queries
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.
1 parent f46acef commit 9c081e8

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/NeptuneSchema.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,22 @@ async function getEdgesNames() {
132132
}
133133

134134

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

145148

146149
async function getEdgesDirections() {
147-
let possibleDirections = [];
148-
for (const edge of schema.edgeStructures) {
149-
for (const fromNode of schema.nodeStructures) {
150-
for (const toNode of schema.nodeStructures) {
151-
possibleDirections.push({edge:edge, from:fromNode.label, to:toNode.label});
152-
}
153-
}
154-
}
155-
156-
await Promise.all(possibleDirections.map(checkEdgeDirection))
150+
await Promise.all(schema.edgeStructures.map(findFromAndToLabels))
157151
}
158152

159153

0 commit comments

Comments
 (0)