refine logging

This commit is contained in:
j 2016-02-13 15:38:56 +05:30
parent 0c5edb38ef
commit 44515eb031

View file

@ -193,19 +193,18 @@ class Peer(object):
current = set([r[1] for r in state.db.session.execute(q)])
library = set(self.library.keys())
remove = list(current - library)
logger.debug('remove %s', len(remove))
u = user.models.User.get(self.id)
listid = u.library.id
lists = [l.id for l in u.lists.all()]
getpreview = []
t0 = time.time()
if remove:
logger.debug('remove %s items', len(remove))
q = item.models.user_items.delete().where(c_user_id.is_(self.id)).where(c_item_id.in_(remove))
state.db.session.execute(q)
q = user.models.list_items.delete().where(l_list_id.in_(lists)).where(l_item_id.in_(remove))
state.db.session.execute(q)
add = list(library - current)
logger.debug('add %s', len(add))
listitems = {}
q = user.models.list_items.select().where(l_list_id.in_(lists))
for row in state.db.session.execute(q):
@ -214,6 +213,7 @@ class Peer(object):
listitems[row['list_id']].add(row['item_id'])
t0 = maybe_commit(t0)
if add:
logger.debug('add %s items', len(add))
t0 = time.time()
q = item.models.user_items.select().where(c_user_id.is_(self.id))
useritems = {r['item_id'] for r in state.db.session.execute(q)}
@ -256,8 +256,8 @@ class Peer(object):
t0 = time.time()
for l in u.lists.all():
if l.name:
logger.debug('update list %s', l.name)
if l.name in remove:
logger.debug('remove list %s', l.name)
l.remove(commit=False)
else:
if l.id in listitems:
@ -268,9 +268,12 @@ class Peer(object):
update_items = list(set(update_items) - set(ladd))
if lremove:
l.remove_items(lremove, commit=False)
if ladd or lremove:
logger.debug('update list %s', l.name)
else:
l.add_items(self.info['lists'][l.name], commit=False)
update_items = list(set(update_items) - set(self.info['lists'][l.name]))
logger.debug('update list %s', l.name)
if state.shutdown:
break
t0 = maybe_commit(t0)
@ -286,9 +289,9 @@ class Peer(object):
update_items = list(set(update_items) - set(self.info['lists'][name]))
if state.shutdown:
break
logger.debug('update %s', len(update_items))
t0 = time.time()
if update_items:
logger.debug('update %s items', len(update_items))
for i in item.models.Item.query.filter(item.models.Item.id.in_(update_items)):
i.update(commit=False)
t0 = maybe_commit(t0)