Social voting on Google App Engine -
i have app users can upvote or downvote blog post. implement voting functionality, created below model ...
class upvote(ndb.model): user_id = ndb.integerproperty(required=true) blog_id = ndb.integerproperty(required=true)
when user upvotes post, save via:
upvote(user_id=user.key.id(), blog_id=blog.key.id()).put()
and see if user has upvoted query:
upvote.query(upvote.user_id=user.key.id(), upvote.blog_id=blog.key.id())
is efficient way implement such voting system? want make sure seems upvote
model can large. of course prematurely optimizing in theoretical situation millions of users want efficient/cheapest method.
well, 1 i'd call model vote
, i'd add booleanproperty
called upvote
, set true
if it's upvote , set false
if it's downvote.
otherwise you'd have repeat story downvotes , without logic you'd leave room user cast 2 votes, 1 , 1 down, same post, imho doesn't make lot of sense.
yes, there many vote
entities, small , not related each-other, scaling pretty good.
Comments
Post a Comment