Query to return all possible routes between two nodes those are not directly connected

Hi,
Please I need a query/procedure that returns all possible routes between two nodes "those are not mandatory to be directly interconnected" in a meshy telecommunications network. The relationship is called an OTS and the order of routes should be based on the Distance/Sum Of Distance of OTS(s). I tried several queries, but they take too much time as far as the network is becoming bigger.

ex.
query = (f"""MATCH (from{{nodeName:"{srcNode}"}}),(to{{nodeName:"{dstNode}"}}),path=(from)-[:ots*1..{hops}]-(to)
WHERE NONE (n IN nodes(path) WHERE size([x IN nodes(path) WHERE n = x]) > 1 )
AND NOT NONE (n IN nodes(path) WHERE n.nodeName IN {includes})
AND NONE (n IN nodes(path) WHERE n.nodeName IN {excludes})
RETURN DISTINCT path AS shortestPath,
reduce(distance = 0, r in relationships(path) | distance + toInteger(r.distance)) AS totalDistance
ORDER BY totalDistance ASC LIMIT {limit}""")

Cypher will not traverse the same relationship more than once, so you do not need to account for looping in your network. Given that, this code is not needed, thus removing a lot of work.

NONE (n IN nodes(path) WHERE size([x IN nodes(path) WHERE n = x]) > 1 )

If the "from" and "to" are the same then this would remove all paths, otherwise you will never see the same node twice.

Also, you don't need to do a RETURN DISTINCT as all paths will already be distinct. This will remove a sort/hash on the paths from the operation.

Finally, can you put a direction on your :ots relationship? Doing so will help performance considerably. Although, in a network this may not be possible.

Let us know how this affects your performance.