
I wasn't planning on diving back into the world of running the voting site teavee.com, but after writing a blog post about the history of the site I couldn't stop thinking about it.
The biggest problem I had back in 2006 was dealing with hosting options. Now that Google App Engine is available and free, it seems there was no excuse. Might as well put teavee back up and see what happens. I took the votay code base and changed a few things around. Biggest lesson learned from votay is to go ahead and repeat data. So I have "Show" objects stored in the DataStore as well as "Winner" objects. Each show and winner model have a title, permalink, summary, and votes. But forget about trying to join a winner's table over to the show table. Instead, at the end of each week I create new Winner objects with the data copied over from the Show objects. When listing winners I have all the data needed. No joins required.
The nature of the real-time voting with rank, trailing show, and leading show make using memcache not a good option. Everything has to come from the data store. When bumping up the vote by one I use "db.run_in_transaction" to select the current object, +1 to the votes and save it again, all in one transaction. The lock out of each user for five minutes however works great in memcache. I just call:
memcache.add(user.user_id(), datetime.now(), 300)
To put into memcache the current time the user last voted with an expiry of five minutes. If there is an object in memcache with a key of the user's id I know not to let them vote. I also know how long ago they last voted and can give them a countdown until the five minutes is done. Then, the expiry handles getting the key out of memcache for me.
I did run into one issue when trying to call the django filter "intcomma" to display a number with commas after every 3rd digit. This filter is not on by default in GAE. I made a file called "intcomma.py" in my root directory with:
from django import template
from django.contrib.humanize.templatetags.humanize import intcomma
register = template.Library()
register.filter('intcomma', intcomma)
Then in my main method I just call:
template.register_template_library('intcomma')
Time will tell if users will come back and vote again. Go ahead and vote for my favorite show please.
|
|













coments test