cache the result of running bleach in the db, too slow to do on render
This commit is contained in:
parent
a4113c9416
commit
fa4064ab31
8 changed files with 59 additions and 17 deletions
27
migrations/20150318-clean-content.py
Normal file
27
migrations/20150318-clean-content.py
Normal 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()
|
Loading…
Add table
Add a link
Reference in a new issue