remove record_ts

This commit is contained in:
j 2016-01-24 12:18:21 +05:30
parent 139f7aee67
commit 4d9d54ad8f
2 changed files with 10 additions and 21 deletions

View file

@ -50,9 +50,16 @@ class Changelog(db.Model):
if '_commit' in kwargs: if '_commit' in kwargs:
commit = kwargs['_commit'] commit = kwargs['_commit']
del kwargs['_commit'] del kwargs['_commit']
if '_ts' in kwargs:
timestamp = kwargs['_ts']
del kwargs['_ts']
else:
timestamp = None
c = cls() c = cls()
c.created = datetime.utcnow() c.created = datetime.utcnow()
c.timestamp = datetime2ts(c.created) if not timestamp:
timestamp = c.created
c.timestamp = datetime2ts(timestamp)
c.user_id = user.id c.user_id = user.id
c.revision = cls.query.filter_by(user_id=user.id).count() c.revision = cls.query.filter_by(user_id=user.id).count()
c.data = json.dumps([action] + list(args), ensure_ascii=False) c.data = json.dumps([action] + list(args), ensure_ascii=False)
@ -63,24 +70,6 @@ class Changelog(db.Model):
state.db.session.commit() state.db.session.commit()
logger.debug('record change: %s', c.json()) logger.debug('record change: %s', c.json())
@classmethod
def record_ts(cls, user, ts, action, *args):
# fixme remove
c = cls()
c.created = datetime.utcnow()
if ts:
c.timestamp = datetime2ts(ts)
else:
c.timestamp = datetime2ts(c.created)
c.user_id = user.id
c.revision = cls.query.filter_by(user_id=user.id).count()
c.data = json.dumps([action] + list(args), ensure_ascii=False)
_data = str(c.revision) + str(c.timestamp) + c.data
_data = _data.encode()
state.db.session.add(c)
state.db.session.commit()
logger.debug('record change: %s', c.json())
@classmethod @classmethod
def apply_changes(cls, user, changes, first=False): def apply_changes(cls, user, changes, first=False):
trigger = changes trigger = changes

View file

@ -308,7 +308,7 @@ class Item(db.Model):
self.update_cover() self.update_cover()
user = state.user() user = state.user()
if record and user in self.users: if record and user in self.users:
Changelog.record_ts(user, modified, 'edititem', self.id, record) Changelog.record(user, 'edititem', self.id, record, _ts=modified)
if 'sharemetadata' in record and not record['sharemetadata']: if 'sharemetadata' in record and not record['sharemetadata']:
self.sync_metadata() self.sync_metadata()
@ -356,7 +356,7 @@ class Item(db.Model):
self.save() self.save()
user = state.user() user = state.user()
if record and user in self.users: if record and user in self.users:
Changelog.record_ts(user, self.modified, 'edititem', self.id, record) Changelog.record(user, 'edititem', self.id, record, _ts=self.modified)
if 'cover' in record: if 'cover' in record:
self.update_cover() self.update_cover()