Hi,
I have web app where each user can have friends. Users can look at different pages on my site, like:
pizza.html
hamburger.html
etc..
If I am userA, and I'm looking at page 'pizza.html', I'd like to know which of my friends have also 'liked' this page. Assuming I want to show this when I load pizza.html, I could do it on demand really painfully like:
User me;
Like current = "pizza.html";
List<User> friendsWhoAlsoLikePageImLookingAt;
for (User friend : me.getFriends()) {
for (Like like : friend.getLikes()) {
if (like == current) {
friendsWhoAlsoLikePageImLookingAt.add(friend);
}
}
}
// now friendsWhoAlsoLikePageImLookingAt contains all of my
// friends that like the page I'm viewing.
that would work, but would scale really poorly, as the # of friends and their likes grows. Is there any algorithm I can look into to solve this?
Another approach would be to precompute all likes for each user (this would not scale that well either I think). For example, each user gets their own txt file per interest like:
userA_pizza.txt
userB_pizza.txt
userA_hamburger.txt
userB_hamburger.txt
...
assuming I'm friends with userB, and userB adds 'pizza.html' as a new like - then I would update the userA_pizza.txt file to look like:
// userA_pizza.txt
userB // latest friend to also like this interest.
userX // previous friend likes
userY // previous friend likes
now whenever I (userA) view the pizza page, I can open 'userA_pizza.txt' and just dump all the friends names without doing any computations. Now every time a user likes a page, I have to update N txt files, where N is the number of their friends. Furthermore, each user would need a text file per possible interest (and there could be thousands of interests). If a user has 100k friends and they each have 1000 interests, this could also be very costly!
Yes so any ideas or thoughts would be great -
Thanks