Most efficient/best way to do favorites or a Digg-style page?


Suppose I'm building a site that lets users mark items as favorites, or as an example, a Digg-style site, where users can vote up or down items... What is the most efficient way to give each item the appropriate context based on whether it has been marked/voted the next time it appears on a list of items for the user? For example, if you Digg something on Digg, it remembers the next time you see that item on a dynamically generated list (whether it's the most popular, front page, etc.) and shows that it has already been dugg and gives you a different set of options for that item.

I see 2 possible solutions, neither of which seems particularly efficient: 1. When loading the page, do a database join of user's diggs with news items to get the status of each item 2. Load all of a user's diggs into memory as an array, and in the view, for each item do something like... if in user_votes then ...

Which of these is better, or is there even a better way?


Thanks for the response. This seems like the most scalable, efficient way to do it, which is exactly what I was looking for. Thanks!