Votes
Now that we have modeled questions and answers in our application, it's time to think about how voting might work.
Let's design it a little:
Users vote answers up and down based on their opinion of them
Answers are ordered by their score so the best ones appear first
Each person is allowed one vote per answer
If a user votes again, they should replace their previous vote
We will make use of a few things we have learned so far in this chapter; transactions will help us ensure the correct score is calculated for answers, and we'll use predictable keys again to ensure that each person gets only one vote per answer.
We will first build a structure to represent each vote and use field tags to be a little more specific about how we want the data store to index our data.
Indexing
Reads from Google Cloud Datastore are extremely fast due to the extensive use of indexes. By default, every field in our structure is indexed. Queries that attempt to filter on fields that aren't indexed will fail (the method...