mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Start database section id update on its own thread
This commit is contained in:
parent
7f1a08dd04
commit
4a65dc1d6e
4 changed files with 68 additions and 68 deletions
|
@ -282,7 +282,7 @@ def initialize_scheduler():
|
||||||
else:
|
else:
|
||||||
seconds = 0
|
seconds = 0
|
||||||
|
|
||||||
if CONFIG.PMS_IP and CONFIG.PMS_TOKEN:
|
if CONFIG.PMS_IP and CONFIG.PMS_TOKEN and CONFIG.UPDATE_SECTION_IDS != -1:
|
||||||
schedule_job(plextv.get_real_pms_url, 'Refresh Plex Server URLs',
|
schedule_job(plextv.get_real_pms_url, 'Refresh Plex Server URLs',
|
||||||
hours=12, minutes=0, seconds=0)
|
hours=12, minutes=0, seconds=0)
|
||||||
schedule_job(pmsconnect.get_server_friendly_name, 'Refresh Plex Server Name',
|
schedule_job(pmsconnect.get_server_friendly_name, 'Refresh Plex Server Name',
|
||||||
|
|
|
@ -16,6 +16,66 @@
|
||||||
from plexpy import logger, datatables, common, database, helpers
|
from plexpy import logger, datatables, common, database, helpers
|
||||||
import plexpy
|
import plexpy
|
||||||
|
|
||||||
|
def update_section_ids():
|
||||||
|
from plexpy import pmsconnect, activity_pinger
|
||||||
|
|
||||||
|
plexpy.CONFIG.UPDATE_SECTION_IDS = -1
|
||||||
|
|
||||||
|
logger.info(u"PlexPy Libraries :: Updating section_id's in database.")
|
||||||
|
|
||||||
|
logger.debug(u"PlexPy Libraries :: Disabling monitoring while update in progress.")
|
||||||
|
plexpy.schedule_job(activity_pinger.check_active_sessions, 'Check for active sessions',
|
||||||
|
hours=0, minutes=0, seconds=0)
|
||||||
|
plexpy.schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
|
||||||
|
hours=0, minutes=0, seconds=0)
|
||||||
|
plexpy.schedule_job(activity_pinger.check_server_response, 'Check for server response',
|
||||||
|
hours=0, minutes=0, seconds=0)
|
||||||
|
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
try:
|
||||||
|
query = 'SELECT id, rating_key FROM session_history_metadata WHERE section_id IS NULL'
|
||||||
|
result = monitor_db.select(query=query)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn(u"PlexPy Libraries :: Unable to execute database query for update_section_ids: %s." % e)
|
||||||
|
|
||||||
|
logger.debug(u"PlexPy Libraries :: Unable to update section_id's in database.")
|
||||||
|
plexpy.CONFIG.__setattr__('UPDATE_SECTION_IDS', 1)
|
||||||
|
plexpy.CONFIG.write()
|
||||||
|
|
||||||
|
logger.debug(u"PlexPy Libraries :: Re-enabling monitoring.")
|
||||||
|
plexpy.initialize_scheduler()
|
||||||
|
return None
|
||||||
|
|
||||||
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
|
|
||||||
|
error_keys = []
|
||||||
|
for item in result:
|
||||||
|
id = item['id']
|
||||||
|
rating_key = item['rating_key']
|
||||||
|
metadata = pms_connect.get_metadata_details(rating_key=rating_key)
|
||||||
|
|
||||||
|
if metadata:
|
||||||
|
metadata = metadata['metadata']
|
||||||
|
section_keys = {'id': id}
|
||||||
|
section_values = {'section_id': metadata['section_id']}
|
||||||
|
monitor_db.upsert('session_history_metadata', key_dict=section_keys, value_dict=section_values)
|
||||||
|
else:
|
||||||
|
error_keys.append(rating_key)
|
||||||
|
|
||||||
|
if error_keys:
|
||||||
|
logger.debug(u"PlexPy Libraries :: Updated all section_id's in database except for rating_keys: %s." %
|
||||||
|
', '.join(str(key) for key in error_keys))
|
||||||
|
else:
|
||||||
|
logger.debug(u"PlexPy Libraries :: Updated all section_id's in database.")
|
||||||
|
|
||||||
|
plexpy.CONFIG.__setattr__('UPDATE_SECTION_IDS', 0)
|
||||||
|
plexpy.CONFIG.write()
|
||||||
|
|
||||||
|
logger.debug(u"PlexPy Libraries :: Re-enabling monitoring.")
|
||||||
|
plexpy.initialize_scheduler()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
class Libraries(object):
|
class Libraries(object):
|
||||||
|
|
||||||
|
@ -655,37 +715,6 @@ class Libraries(object):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"PlexPy Libraries :: Unable to execute database query for undelete: %s." % e)
|
logger.warn(u"PlexPy Libraries :: Unable to execute database query for undelete: %s." % e)
|
||||||
|
|
||||||
def update_section_ids(self):
|
|
||||||
from plexpy import pmsconnect
|
|
||||||
|
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
|
||||||
monitor_db = database.MonitorDatabase()
|
|
||||||
|
|
||||||
try:
|
|
||||||
query = 'SELECT id, rating_key FROM session_history_metadata WHERE section_id IS NULL'
|
|
||||||
result = monitor_db.select(query=query)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn(u"PlexPy Libraries :: Unable to execute database query for update_section_ids: %s." % e)
|
|
||||||
return None
|
|
||||||
|
|
||||||
for item in result:
|
|
||||||
id = item['id']
|
|
||||||
rating_key = item['rating_key']
|
|
||||||
|
|
||||||
result = pms_connect.get_metadata_details(rating_key=rating_key)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
metadata = result['metadata']
|
|
||||||
|
|
||||||
section_keys = {'id': id}
|
|
||||||
section_values = {'section_id': metadata['section_id']}
|
|
||||||
|
|
||||||
monitor_db.upsert('session_history_metadata', key_dict=section_keys, value_dict=section_values)
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def delete_datatable_media_info_cache(self, section_id=None):
|
def delete_datatable_media_info_cache(self, section_id=None):
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,6 @@ def get_server_friendly_name():
|
||||||
return server_name
|
return server_name
|
||||||
|
|
||||||
def refresh_libraries():
|
def refresh_libraries():
|
||||||
from plexpy import activity_pinger
|
|
||||||
|
|
||||||
logger.info(u"PlexPy Pmsconnect :: Requesting libraries list refresh...")
|
logger.info(u"PlexPy Pmsconnect :: Requesting libraries list refresh...")
|
||||||
library_sections = PmsConnect().get_library_details()
|
library_sections = PmsConnect().get_library_details()
|
||||||
|
|
||||||
|
@ -76,32 +74,9 @@ def refresh_libraries():
|
||||||
|
|
||||||
if plexpy.CONFIG.UPDATE_SECTION_IDS == 1:
|
if plexpy.CONFIG.UPDATE_SECTION_IDS == 1:
|
||||||
from plexpy import libraries
|
from plexpy import libraries
|
||||||
|
import threading
|
||||||
|
|
||||||
plexpy.CONFIG.UPDATE_SECTION_IDS = -1
|
threading.Thread(target=libraries.update_section_ids).start()
|
||||||
|
|
||||||
logger.info(u"PlexPy Pmsconnect :: Updating section_id's in database.")
|
|
||||||
|
|
||||||
logger.debug(u"PlexPy Pmsconnect :: Disabling monitoring while update in progress.")
|
|
||||||
plexpy.schedule_job(activity_pinger.check_active_sessions, 'Check for active sessions',
|
|
||||||
hours=0, minutes=0, seconds=0)
|
|
||||||
plexpy.schedule_job(activity_pinger.check_recently_added, 'Check for recently added items',
|
|
||||||
hours=0, minutes=0, seconds=0)
|
|
||||||
plexpy.schedule_job(activity_pinger.check_server_response, 'Check for server response',
|
|
||||||
hours=0, minutes=0, seconds=0)
|
|
||||||
|
|
||||||
result = libraries.Libraries().update_section_ids()
|
|
||||||
|
|
||||||
if result:
|
|
||||||
logger.debug(u"PlexPy Pmsconnect :: Updated all section_id's in database.")
|
|
||||||
plexpy.CONFIG.__setattr__('UPDATE_SECTION_IDS', 0)
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
else:
|
|
||||||
logger.debug(u"PlexPy Pmsconnect :: Unable to update section_id's in database.")
|
|
||||||
plexpy.CONFIG.__setattr__('UPDATE_SECTION_IDS', 1)
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
|
|
||||||
logger.debug(u"PlexPy Pmsconnect :: Re-enabling monitoring.")
|
|
||||||
plexpy.initialize_scheduler()
|
|
||||||
|
|
||||||
logger.info(u"PlexPy Pmsconnect :: Libraries list refreshed.")
|
logger.info(u"PlexPy Pmsconnect :: Libraries list refreshed.")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -436,18 +436,14 @@ class WebInterface(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def update_section_ids(self, **kwargs):
|
def update_section_ids(self, **kwargs):
|
||||||
|
|
||||||
logger.debug(u"Updating section_id's in database.")
|
logger.debug(u"Manual database section_id update called.")
|
||||||
library_data = libraries.Libraries()
|
|
||||||
result = library_data.update_section_ids()
|
result = libraries.update_section_ids()
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
logger.debug(u"Updated all section_id's in database.")
|
return "Updated all section_id's in database."
|
||||||
plexpy.CONFIG.UPDATE_SECTION_IDS = 0
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
return "Section ids updated."
|
|
||||||
else:
|
else:
|
||||||
logger.debug(u"Unable to update section_id's in database.")
|
return "Unable to update section_id's in database. See logs for details."
|
||||||
return "Unable to update section ids in database."
|
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def delete_datatable_media_info_cache(self, section_id, **kwargs):
|
def delete_datatable_media_info_cache(self, section_id, **kwargs):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue