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: