I have a graph where the nodes are US cities and edges are the cost to travel between cities. I have data about the cost(edges) coming in constantly and need a quick way to insert the edges. Here's what I want to do: Let's say the current incoming data is
"New York, New York; Los Angeles, California; 1000"
- Case 1(no edge exists between NYC and LA): Create edge with cost of 1000
- Case 2a(edge exists but cost is higher than 1000): Replace cost with 1000
- Case 2b(edge exists and cost is lower than 1000): Do nothing
Currently, my cypher query looks like this:
MERGE (a:City{name:"New York, New York"})-[r:TO]->(b:City{name:"Los Angeles"})
SET r.price = CASE WHEN (NOT exists(r.price) OR r.price>1000)THEN 1000 ELSE r.price END
This took ~100ms to finish on my computer and is too slow for my application. Is there a faster way to do it?