How to structure an efficient points logging system in PHP/MySQL -
i have points system on blog type website, users can earn points contributing in different ways (commenting/ voting on posts/ voting on comments etc). how go logging points earned user in mysql database efficiently.
currently i'm thinking of having following fields in it's own table:
post_id, giving_user_id, receiving_user_id, type, date_added now, if site grows , have 1 million ... 500 million... 1 billion rows, approach , structure able hold without taking forever run, providing data types set correctly?
i'll inserting table, want able show previous 20 (example) points award/deducted in future, similar stackoverflow user stats pages.
is there more efficient structure better me?
updated info
yes stackoverflow in functionality, 1 user gets 1 vote per postid. @paul gregory after rethink removing receiving_user_id may better idea related post.
assuming can use post_id identify specific comment, , using type sensibly (as number other ids), approach broadly perfect log.
(i don't know receiving_user_id tells don't know post_id - hope you're not expecting distinguish between posts , comments).
it not, however, efficient if going use table calculate total points each time need it.
you should therefore store current totals separately - against each post/comment.
as want show last 20 points, should write exports log data , removes old log entries every often.
Comments
Post a Comment