cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Get friend posts with comments and likes

I'm new to neo4j and tried making a query that gets the following:

  • all stories of friends that haven't been seen by the user & aren't private
  • comments of friends on that story
  • likes of friends on that story

My query looks like this:

Match (P:User {id: 5})
Match (a:Story)-[BEL_TO]->(P2: User)-[:FRI]-(P)
Where not (P)-[:SEEN]->(a) AND NOT a.priv = "bf"
optional Match (a)<-[:LIKE]-(P3: User)-[:FRI]-(P)
with a, COLLECT({id: P3.id, name: P3.name}) as flikes
optional Match (a)<-[:COM_ON]-(com:Com)-[:BEL_TO]->(P4: User)-[:FRI]-(P) 
RETURN a.id as id, flikes, COLLECT({id: P4.id, name: P4.name, comment: com}) as fcomments
LIMIT 35

When I run this query, I get the results I want, but I tested the query in the following scenario:

  • 1000 "new" posts (no relation seen)
  • 50 likes and comments on each post
  • user has 1000 friends

The query takes around 1500 ms

Is there a way to make this query more efficient/faster ?

Things I thought of:

  • adding an index (but don't know where)
  • using "join on a" (but gave errors in neo4j)

Thanks in advance.

Screenshot of profiler:

1 REPLY 1

Hi @karel.debedts1

You can run the "create index" only once before your Cypher.

CREATE INDEX index_priv FOR (a:Story) ON (a.priv);
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online