cache the result of running bleach in the db, too slow to do on render

This commit is contained in:
Kyle Mahan 2015-03-18 08:53:37 -07:00
parent a4113c9416
commit fa4064ab31
8 changed files with 59 additions and 17 deletions

View file

@ -0,0 +1,27 @@
from config import Config
import sqlalchemy
import sqlalchemy.orm
from woodwind.models import Entry
from woodwind import util
engine = sqlalchemy.create_engine(Config.SQLALCHEMY_DATABASE_URI)
Session = sqlalchemy.orm.sessionmaker(bind=engine)
try:
engine.execute('alter table entry add column content_cleaned text')
except:
pass
try:
session = Session()
for entry in session.query(Entry).all():
print('processing', entry.id)
entry.content_cleaned = util.clean(entry.content)
session.commit()
except:
session.rollback()
raise
finally:
session.close()