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:
When loading the page, do a database join of user’s diggs with news
items to get the status of each item
Load all of a user’s diggs into memory as an array, and in the
view, for each item do something like… if item.id in user_votes
then …
Which of these is better, or is there even a better way?
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?
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:
When loading the page, do a database join of user’s diggs with news
items to get the status of each item
Load all of a user’s diggs into memory as an array, and in the
view, for each item do something like… if item.id in user_votes
then …
Which of these is better, or is there even a better way?
how about this;
grab all the content you’re going to display,
then grab all the user_diggs for those content_ids