log db sync

This commit is contained in:
j 2016-02-24 12:43:55 +05:30
parent 9744653701
commit c8722855e2

View file

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