add ability to disable inserting to history table

add delayed insert to history table
This commit is contained in:
mixedpuppy 2010-10-18 13:58:21 -07:00
Родитель a1ea06eb38
Коммит 0a40f07a3e
2 изменённых файлов: 30 добавлений и 12 удалений

Просмотреть файл

@ -97,19 +97,16 @@ The 'send' namespace is used to send updates to our supported services.
else:
# create a new record in the history table.
assert result
history = History()
history.account_id = acct.get('id')
history.published = UTCDateTime.now()
for key, val in request.POST.items():
setattr(history, key, val)
Session.add(history)
# remove for now until we have a need to do this
#link = sign_link(shorturl, acct.username)
Session.commit()
result['linkdrop'] = history.id
if asbool(config.get('history_enabled', True)):
history = History()
history.account_id = acct.get('id')
history.published = UTCDateTime.now()
for key, val in request.POST.items():
setattr(history, key, val)
Session.add(history)
Session.commit()
result['shorturl'] = shorturl
result['from'] = userid
result['to'] = to
log.info("send success - linkdrop id is %s", history.id)
# no redirects requests, just return the response.
return {'result': result, 'error': error}

Просмотреть файл

@ -9,12 +9,33 @@ from linkdrop.model.serializer_mixin import SerializerMixin
from linkdrop.model.account import Account
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import expression
from pylons import config
from paste.deploy.converters import asbool
@compiles(expression.Insert)
def annotated_insert(insert, compiler, **kw):
if getattr(insert.table, 'insert_prefix', None):
insert = insert.prefix_with('%s' % insert.table.insert_prefix)
return compiler.visit_insert(insert, **kw)
class History(JsonExpandoMixin, SerializerMixin, Base):
__tablename__ = 'history'
__table_args__ = make_table_args()
# we use ISAM for this table so we can do delayed inserts
__table_args__ = make_table_args(mysql_engine = 'MyISAM')
id = Column(Integer, primary_key=True)
account_id = Column(None, ForeignKey(Account.id), index=True)
published = Column(UTCDateTime, nullable=False)
account = relationship('Account')
def __init__(self):
# a one time modification to the table so insert statments
# get modified properly
if asbool(config.get('delayed_inserts', False)) and not \
hasattr('insert_prefix', History.__table__):
History.__table__.insert_prefix = 'DELAYED'