Last post Dec 12, 2010 04:30 PM by KyleMBurns
Dec 12, 2010 07:54 AM|huttye3|LINK
I am trying to create a comments page for users to review and comment on an article. I have 2 buttons on each comments posted by users; "Like" and "Don't Like". I am stuck with how to track which user voted already for a given comment. I am thinking of two
options and would like to know if they are they way to go or is there a better solution.
Option 1: I have created a table in my database with stores, the comment id, the userid of the user who rated it and the value "like" or "don't like". So each time I have to query my table to find out if this user indeed vote for a given comment. The table
unfortunately grows exponentially!!
Option 2: I store the commentid, userid, and "like" or "don't like" value in a cookie on the client's machine. I read the cookie and find out if the user has already voted on a comment. This is proving to be VERY quirky with cookie expiration, growing cookie
size and also multiple users on the same machine.
In either way, my test case of ~1500 users, and 2 Million comments, this is getting to be HEAVY on both methods. Is there anything better?
Thanks in Advance!!!
Dec 12, 2010 09:32 AM|KyleMBurns|LINK
If you are ever going to need to perform analytics on things like "how many people like this comment", then storing the data persistantly on the server is the only option available to you at all. I think it would be quite a feat to get 1500 people to actually
read and vote for 2 million comments each, so your test case may work based on the mathematics but is probably more of a theoritical bound than a practical one. If you do have that much dedication from your end users, storing in the cookie would quickly chew
up the recommended 4k limitation for cookies - not to mention frustrated users who lose their work after clearing the cookie cache. I would say treat this like data and put it in the database.
Dec 12, 2010 12:06 PM|huttye3|LINK
Thanks! It does make sense to use the database to store users' votes.
I did notice in some websites, I can vote without having to even login or signing up. How do they accomplish this?
Dec 12, 2010 04:30 PM|KyleMBurns|LINK
It's all a matter of whether they care who is voting. If you need to provide a report that says "Joe Smith liked these comments...", then your needs cannot be met without users first identifying themselves. If you just need to know how many people liked
which comments, there is no need for the user to identifying himself. Things like writing an identifying guid into a cookie so that you can tie together votes help, but only so long as it is OK for the cookie to disappear at some point in time.