sqlalchemy session fixes

here's an attempt to solve the connection pool exhaustion problem we saw on the production box.

Based on the documentation and some blogs, it's recommended to use scoped_session, turn on pool_recycle, and implement @app.teardown. Will run this for a few days on prod box before merging.

REFS:
http://mofanim.wordpress.com/2013/01/02/sqlalchemy-mysql-has-gone-away/
http://flask.pocoo.org/docs/0.10/patterns/sqlalchemy/