log db sync

This commit is contained in:
j 2016-02-24 12:43:55 +05:30
parent 9744653701
commit c8722855e2
1 changed files with 6 additions and 0 deletions

View File

@ -311,6 +311,7 @@ class Peer(object):
def sync_db():
from sqlalchemy.orm import load_only
import item.models
first = True
with db.session():
sort_ids = {i.item_id for i in item.models.Sort.query.options(load_only('item_id'))}
if sort_ids:
@ -318,6 +319,9 @@ def sync_db():
commit = False
for i in item.models.Item.query.options(load_only('id')):
if i.id not in sort_ids:
if first:
first = False
logger.debug('sync items')
i.update(commit=False)
if i.info['mediastate'] == 'unavailable' and state.tasks:
state.tasks.queue('getpreview', i.id)
@ -328,6 +332,8 @@ def sync_db():
break
if commit:
state.db.session.commit()
if not first:
logger.debug('synced items')
if not state.shutdown:
cleanup_lists()
if not state.shutdown: