parse_resource speed ups and memory management

@Bjwebb this should help with some of the memory issues and speed issues.

The main problem is with the flask-sqlalchemy debug mode http://pythonhosted.org/Flask-SQLAlchemy/config.html . If on it saves all the queries made as a _DebugQueryTuple, this build up over time for large files as more and more queries are commited to the database. I think this is the general cause for parsing to eat up lots of memory.

I've changed the parsing code as well to flush objects to the database first before commiting, this is generally a bit quicker so should speed up the parsing as well.

Locally I ended up parsing the http://api.openaid.se/documents/xml/998.xml still took 7 mins. I don't know how much slower it'll be on one of the heroku dynos, but the memory usage was limited by an upper bound. releveant to #162. This might not fix all our memory issues however.