queue previews after sync

This commit is contained in:
j 2021-01-31 16:12:12 +01:00
parent 5b6ef3d669
commit ab7863807b
3 changed files with 19 additions and 3 deletions

View file

@ -377,6 +377,10 @@ def sync_db():
from sqlalchemy.orm import load_only from sqlalchemy.orm import load_only
import item.models import item.models
first = True first = True
missing_previews = []
state.sync_db = True
#FIXME: why is this loop needed
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:
@ -387,9 +391,11 @@ def sync_db():
if first: if first:
first = False first = False
logger.debug('sync items') logger.debug('sync items')
i.update(commit=False) #why?
if i.info.get('mediastate') == 'unavailable' and state.tasks: #i.update(commit=False)
state.tasks.queue('getpreview', i.id) i.update_sort(commit=False)
if i.info.get('mediastate') == 'unavailable':
missing_previews.append(i.id)
commit = True commit = True
#logger.debug('sync:%s', i) #logger.debug('sync:%s', i)
t0 = maybe_commit(t0) t0 = maybe_commit(t0)
@ -397,6 +403,7 @@ def sync_db():
break break
if commit: if commit:
state.db.session.commit() state.db.session.commit()
if not first: if not first:
logger.debug('synced items') logger.debug('synced items')
if not state.shutdown: if not state.shutdown:
@ -408,6 +415,12 @@ def sync_db():
item.models.Sort.query.filter_by(item_id=None).delete() item.models.Sort.query.filter_by(item_id=None).delete()
item.models.Find.query.filter_by(item_id=None).delete() item.models.Find.query.filter_by(item_id=None).delete()
if missing_previews and state.tasks:
logger.debug('queueing download of %s missing previews', len(missing_previews))
for id in missing_previews:
state.tasks.queue('getpreview', id)
state.sync_db = False
def cleanup_lists(): def cleanup_lists():
import item.models import item.models
import user.models import user.models

View file

@ -598,6 +598,8 @@ class Nodes(Thread):
def _pull(self): def _pull(self):
if not state.sync_enabled or settings.preferences.get('downloadRate') == 0: if not state.sync_enabled or settings.preferences.get('downloadRate') == 0:
return return
if state.sync_db:
return
if state.activity and state.activity.get('activity') == 'import': if state.activity and state.activity.get('activity') == 'import':
return return
self._pulling = True self._pulling = True

View file

@ -16,6 +16,7 @@ websockets = []
uisockets = [] uisockets = []
peers = {} peers = {}
changelog_size = None changelog_size = None
sync_db = False
activity = {} activity = {}
removepeer = {} removepeer = {}