Answer the question
In order to leave comments, you need to log in
How do you count the total number of friends in VK?
How does VK count the total number of friends so quickly?
Well, how to optimize this process?
If there is a table with users and a separate one with friends connections (user-user)
After all, then for each user, from the user, you will have to take more of his users and compare if the first user has a friend-user-user
. You will also have to do a loop in a loop and each iteration to db
How can this process be simplified?
Answer the question
In order to leave comments, you need to log in
Conditionally 2 tables with friends of both users are taken and compared. The number of matches is "common" friends. What is the actual problem? Joins and IN() to help.
Graph database
Such DBMSs are architecturally adapted to execute queries like "is vertex A reachable from B?" or "what vertices are reachable from A in two transitions?". See an example from the documentation for Cypher, a query language for Neo4j.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question