What I'm doing is to get all profiles* who has a specific directed relation to a users profile* and if those have an alternate profile* get those in case the users alternate profile* has a relation to it. I also need the direction of the relations.
My problem is, with about 10000 nodes it takes about 5 seconds to get data. I have auto index on nodes and relationships.
This is how my nodes are related:
User-[:profile]->ProfileA-[:related]->ProfileB<-[?:me]->ProfileB2<-[?:related]-ProfileA2<-[:profile]-User
My query looks like this:
START User=node({source})
MATCH User-[:profile]->ProfileA-[rel:related]->ProfileB
WHERE User-->ProfileA-->ProfileB
WITH ProfileA, rel, ProfileB
MATCH ProfileB<-[?:me]->ProfileB2<-[relB?:related]-ProfileA2<-[:profile]-User
WHERE relB IS NULL OR User-->ProfileA-->ProfileB<-->ProfileB2<--ProfileA2<--User
RETURN ProfileB, COLLECT(ProfileB2), rel, relB
LIMIT 25
Any idea how I can optimize the query?
- profiles: ProfileB
- users profile: ProfileA
- alternate profile: ProfileB2
- users alternate profile: ProfileA2