I'm looking for an efficient way to find an (the) edge(s) between two nodes.
I have a requirement that when I add an edge between two specific nodes that I
first determine if the edge already exists, which leads to the need for a
method that return such an edge given the subject and object. Since I was
unable to find such a method I attempted to create my own, which worked, but
has become the performance bottleneck in the code.
private Relationship getSingeRelationship(Node subject, Node object,
RelationshipType relationshipType, String key)
{
for (Relationship relationship : getCommonRelationships(subject, object,
relationshipType, Direction.OUTGOING))
{
boolean currentHasIndex = relationship.hasProperty(EDGE_INDEX_KEY);
if (key == null)
{
if (!currentHasIndex)
{
return relationship;
}
}
else
{
if (currentHasIndex &&
key.equals(relationship.getProperty(EDGE_INDEX_KEY)))
{
return relationship;
}
}
}
return null;
}
...where getCommonRelationships returns an Iterable<Relationship> and simply
loops through all the subject's relationships (of the specified relationship
type and direction) until it finds an edge that points to the given object
node. The profiler says the 2/3 of the time is spent in
org.neo4j.kernel.impl.core.IntArrayIterator.hasNext() and most of the rest is
spent in org.neo4j.kernel.impl.core.RelationshipProxy.getOtherNode(Node).
I am aware of the lab code that is supposed to support indexed edges and could
see using that as a solution, but I was hoping for something native (and merged
into the 1.1-SNAPSHOT branch).
Are there any better approaches?
Thanks,
-Paul
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user