Reduce CPU strain for artwork caching progress

- Fixes #477
This commit is contained in:
Croneter 2018-05-18 15:59:26 +02:00
parent d706f38f91
commit 84c2aa7fa0
2 changed files with 20 additions and 24 deletions

View file

@ -65,23 +65,17 @@ class Image_Cache_Thread(Thread):
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
return
sleep(1000)
# Update the caching state in the PKC settings. Avoid saving '0'
counter += 1
if counter > 10:
counter = 0
length = queue.qsize()
if not set_zero:
settings('caching_artwork_count', value=str(length))
set_zero = False if length else True
elif length:
settings('caching_artwork_count', value=str(length))
set_zero = False
try:
url = queue.get(block=False)
except Empty:
if not set_zero:
# Avoid saving '0' all the time
set_zero = True
settings('caching_artwork_count', value='0')
sleep(1000)
continue
set_zero = False
if isinstance(url, ArtworkSyncMessage):
if state.IMAGE_SYNC_NOTIFICATIONS:
dialog('notification',
@ -133,6 +127,11 @@ class Image_Cache_Thread(Thread):
# We did not even get a timeout
break
queue.task_done()
# Update the caching state in the PKC settings.
counter += 1
if counter > 20:
counter = 0
settings('caching_artwork_count', value=str(queue.qsize()))
# Sleep for a bit to reduce CPU strain
sleep(sleep_between)
LOG.info("---===### Stopped Image_Cache_Thread ###===---")

View file

@ -60,25 +60,17 @@ class ThreadedProcessFanart(Thread):
LOG.info("---===### Stopped FanartSync ###===---")
return
sleep(1000)
# Update the caching state in the PKC settings. Avoid saving '0'
counter += 1
if counter > 10:
counter = 0
length = queue.qsize()
if not set_zero:
settings('fanarttv_lookups', value=str(length))
set_zero = False if length else True
elif length:
settings('fanarttv_lookups', value=str(length))
set_zero = False
# grabs Plex item from queue
try:
item = queue.get(block=False)
except Empty:
if not set_zero:
# Avoid saving '0' all the time
set_zero = True
settings('fanarttv_lookups', value='0')
sleep(200)
continue
set_zero = False
if isinstance(item, ArtworkSyncMessage):
if state.IMAGE_SYNC_NOTIFICATIONS:
dialog('notification',
@ -98,5 +90,10 @@ class ThreadedProcessFanart(Thread):
LOG.debug('Done getting fanart for Plex id %s', item['plex_id'])
with plexdb.Get_Plex_DB() as plex_db:
plex_db.set_fanart_synched(item['plex_id'])
# Update the caching state in the PKC settings. Avoid saving '0'
counter += 1
if counter > 10:
counter = 0
settings('fanarttv_lookups', value=str(queue.qsize()))
queue.task_done()
LOG.debug("---===### Stopped FanartSync ###===---")