I want to know that what is the difference between findById(id,2) vs 2 db calls.
which one is better in terms of performance.
The most matching answer is: it depends!
If you go with the depth=2 option, the query will get one or more additional parts (list comprehensions) in its return clause depending on you data model.
So the questions are:
- Do you have a lot of different relationships on the first and second level?
- Do you need all the data from all the relationships?
Here is my personal rule of thumb:
- If you answer the second question with yes and the amount of data from question 1 does not exceed your application machine's memory, it will be the best option to get everything within one call.
- If you have a lot of different relationships but you do only need a few fields: go with a second db call or think about creating just one custom Cypher query.