2nd, 3rd degree network?

What is the most efficient way to fetch a 2nd degree network (friends and friends of friends) of a node in a social graph?

I tried this:

MATCH (startNode:User {nodeId: 1}) // Find the starting User node
MATCH (startNode)-[*1..2]-(connectedNode:User) // Find distinct User nodes within 1 to 2 hops
WHERE startNode <> connectedNode // Exclude the starting node itself
RETURN count(DISTINCT connectedNode) AS secondDegreeNetworkSize;

I decided to try it on a real social network dataset (40 million nodes, 1 billion edges) from one of the public collections, and it took 130 seconds to fetch and count the nodes in the 2nd degree network of 2.9 million nodes. On average, the users have couple hundred connections or less, but there are outliers, of course.

It took longer than I was willing to wait (I aborted) to compute the 3rd degree networkβ€”even though at first I thought it should be easy.

  1. I am new to cypher and graph databasesβ€”a student trying to learn. Is this the best it can do, or can my query be optimized?
  2. Is there a more suitable data solution for this task that can solve this problem in a smaller amount of time?

I think I read somewhere that graph databases can make tens or even hundreds of millions of traversals per second per core on a modern CPU, and I ran it on a powerful M3Max MacBook with way more RAM than the database size, but even a 2nd degree network of just 1 million nodes took 30 seconds to compute.

So, did I do it wrong? Seems a bit slow for my hardware.

Thanks!

P.S. The schema:

╒══════════════════════════════════════════════════════════════════════╀══════════════════════════════╕
β”‚nodes                                                                 β”‚relationships                 β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ══════════════════════════════║
β”‚[(:User {name: "User",indexes: [],constraints: ["Constraint( id=4, namβ”‚[[:FOLLOWS {name: "FOLLOWS"}]]β”‚
β”‚e='user_nodeId_unique', type='UNIQUENESS', schema=(:User {nodeId}), owβ”‚                              β”‚
β”‚nedIndex=3 )"]})]                                                     β”‚                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜