Reputation: 15090
I'm trying create a relationship between 2 nodes A and B.
A potentially has several hundreds of connections and B may be a newly created node.
The way i'm doing it right now is by loading A with depth of 1, adding B as a child of A and then saving A with a depth of 1
Some example Groovy code,
def B = neo4jOperations.save(new B(), 0)
def A = neo4jOperations.load(A, idOfA, 1)
A.relationshipList().add(B)
neo4jOperations.save(A, 1) // This turns out to be slow since it is saving all the @EndNode of A, while it doesn't need to
This however, is VERY VERY slow due to neo4j loading and saving unnecessary nodes and relationships. I'm only interested to add one node i.e B to the existing relationships of A
Am I hitting an anti-pattern? Or is this the way its supposed to work? Is there a faster way i can do this?
Upvotes: 2
Views: 1067
Reputation: 19373
At the moment, the OGM will load all relationships of A, but will not save them if already persisted. It should not be this slow (which version do you use?). A workaround/hack is to try on a new Session
, load A to depth 0, then add B to it and save. Make sure you don't use this session for any further work because things could go horribly wrong. Better still would be to send us some sample code and open an issue at https://github.com/neo4j/neo4j-ogm
Upvotes: 1