diff --git a/oml/library.py b/oml/library.py index 176bb56..fe321ff 100644 --- a/oml/library.py +++ b/oml/library.py @@ -316,7 +316,7 @@ def sync_db(): if sort_ids: t0 = time.time() commit = False - for i in item.models.Item.query: + for i in item.models.Item.query.options(load_only('id')): if i.id not in sort_ids: i.update(commit=False) if i.info['mediastate'] == 'unavailable' and state.tasks: @@ -324,12 +324,14 @@ def sync_db(): commit = True #logger.debug('sync:%s', i) t0 = maybe_commit(t0) - if state.shutdown: - break + if state.shutdown: + break if commit: state.db.session.commit() - cleanup_lists() - cleanup_peers() + if not state.shutdown: + cleanup_lists() + if not state.shutdown: + cleanup_peers() def cleanup_lists(): import item.models