I have an app where users can upvote or downvote a blog post. To implement the voting functionality, I created the below model ...
class Upvote(ndb.Model):
user_id = ndb.IntegerProperty(required=True)
blog_id = ndb.IntegerProperty(required=True)
When an user upvotes a post, I save it via:
Upvote(user_id=User.key.id(), blog_id=Blog.key.id()).put()
And to see if an user has already upvoted I query:
Upvote.query(Upvote.user_id=User.key.id(), Upvote.blog_id=Blog.key.id())
Is this the most efficient way to implement such a voting system? I want to make sure as it seems the Upvote
model can get very large. Of course I am prematurely optimizing now but in a theoretical situation with millions of users I want the most efficient/cheapest method.