I use this query to relate some nodes between other nodes that the user has.
The problem I have is that when a lot of relationships are created, it takes longer and longer.
I'm trying to find the bottleneck here but I'm missing why or what.
If you can help me i would appreciate.
TL;DR here is my query to be optimized
WITH
[
{ "sender":123, "target":124, "label":"fruit", "bidirectional":true},
{ "sender":123, "target":125, "label":"vegetable", "bidirectional":false}
] as input
MATCH (s) <-[:HAS]-(user:User {author:"me"})-[:HAS]->(t)
UNWIND input as relationship
WITH s,t,relationship
WHERE ID(s) = relationship.sender AND ID(t) = relationship.target
MERGE (s)-[:HAS {label: relationship.label}]->(t)
WITH s,t,relationship
WHERE relationship.bidirectional = true
MERGE (t)-[:HAS {label: relationship.label}]->(s)
The WITH clause is replaced by parameters I send to the query, input in my original query is $input.
I found this link interesting (cypher - How can I optimise a Neo4j MERGE query on a node with many relationships? - Stack Overflow)
Thank you