Search code examples
database-designvoting

If I am allowing users to vote if only they are registered users... what other problems could arise?


Suppose I am allowing users to vote only if they are registered users. I should limit each user to vote only once per article?
I should maintain a table with 4 columns - articleid, userid, bit (to indicate positive/negative) and a datetime column.

Do you still see this being abused?

to obtain net rating, I would query the table twice - once to count all votes that are positive and once to count all votes that are negative.

Please tell me any flaws/optimizations in my approach that you see.


Solution

  • Keeping voting to registered users avoids abuse, revoting through different IP adresses.

    To obtain the net rating, you query the table once, to sum all the votes, or better yet, you keep a tally on each item of the final vote. Voting once means you increment or decrement the rating of the item.

    EDIT: I must insist that querying multiple tables is bad practice if you can pre-calculate it. Breaking up relational models is a big part of database optimisation.