Improve startup speed by refreshing on a separate thread

This commit is contained in:
JonnyWong16 2020-10-25 13:07:42 -07:00
parent 8157ee7811
commit 558023e18e
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
5 changed files with 122 additions and 77 deletions

View file

@ -750,7 +750,9 @@ a .users-poster-face:hover {
position: relative; position: relative;
} }
#dashboard-checking-activity, #dashboard-checking-activity,
#dashboard-no-activity { #dashboard-no-activity,
#dashboard-checking-recently-added,
#dashboard-no-recently-added {
margin-bottom: 20px; margin-bottom: 20px;
} }
.dashboard-activity-instance { .dashboard-activity-instance {
@ -1446,9 +1448,6 @@ a:hover .dashboard-stats-square {
-moz-box-shadow: inset 0 0 0 2px #e9a049; -moz-box-shadow: inset 0 0 0 2px #e9a049;
box-shadow: inset 0 0 0 2px #e9a049; box-shadow: inset 0 0 0 2px #e9a049;
} }
#dashboard-no-recently-added {
margin-bottom: 20px;
}
.dashboard-recent-media-row { .dashboard-recent-media-row {
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;

View file

@ -24,17 +24,13 @@
</div> </div>
<div id="currentActivity"> <div id="currentActivity">
% if PLEX_SERVER_UP: % if PLEX_SERVER_UP:
<div class="text-muted" id="dashboard-checking-activity"><i class="fa fa-refresh fa-spin"></i> Checking for activity...</div> <div class="text-muted" id="dashboard-checking-activity"><i class="fa fa-refresh fa-spin"></i>&nbsp; Checking for activity...</div>
% elif config['pms_is_cloud']: % elif config['pms_is_cloud']:
<div id="dashboard-no-activity" class="text-muted">Plex Cloud server is sleeping.</div> <div id="dashboard-no-activity" class="text-muted">Plex Cloud server is sleeping.</div>
% elif not config['first_run_complete']: % elif not config['first_run_complete']:
<div id="dashboard-no-activity" class="text-muted">The Tautulli setup wizard has not been completed. Please click <a href="welcome">here</a> to go to the setup wizard.</div> <div id="dashboard-no-activity" class="text-muted">The Tautulli setup wizard has not been completed. Please click <a href="welcome">here</a> to go to the setup wizard.</div>
% else: % else:
<div id="dashboard-no-activity" class="text-muted">There was an error communicating with your Plex Server. <div class="text-muted" id="dashboard-checking-activity"><i class="fa fa-refresh fa-spin"></i>&nbsp; Tautulli is connecting to the Plex server...</div>
% if _session['user_group'] == 'admin':
Check the <a href="logs">logs</a> and verify your server connection in the <a href="settings#tab_tabs-plex_media_server">settings</a>.
% endif
</div>
% endif % endif
</div> </div>
</div> </div>
@ -65,7 +61,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div id="home-stats" class="home-platforms"> <div id="home-stats" class="home-platforms">
<div class="text-muted"><i class="fa fa-refresh fa-spin"></i> Loading stats...</div> <div class="text-muted"><i class="fa fa-refresh fa-spin"></i>&nbsp; Loading stats...</div>
<br> <br>
</div> </div>
</div> </div>
@ -84,7 +80,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div id="library-stats" class="library-platforms"> <div id="library-stats" class="library-platforms">
<div class="text-muted"><i class="fa fa-refresh fa-spin"></i> Loading stats...</div> <div class="text-muted"><i class="fa fa-refresh fa-spin"></i>&nbsp; Loading stats...</div>
<br> <br>
</div> </div>
</div> </div>
@ -132,18 +128,13 @@
<div class="col-md-12"> <div class="col-md-12">
<div id="recentlyAdded" style="margin-right: -15px;"> <div id="recentlyAdded" style="margin-right: -15px;">
% if PLEX_SERVER_UP: % if PLEX_SERVER_UP:
<div class="text-muted"><i class="fa fa-refresh fa-spin"></i> Looking for new items...</div> <div id="dashboard-checking-recently-added" class="text-muted"><i class="fa fa-refresh fa-spin"></i>&nbsp; Looking for new items...</div>
% elif config['pms_is_cloud']: % elif config['pms_is_cloud']:
<div class="text-muted">Plex Cloud server is sleeping.</div> <div class="text-muted">Plex Cloud server is sleeping.</div>
% else: % else:
<div class="text-muted">There was an error communicating with your Plex Server. <div id="dashboard-no-recently-added" class="text-muted"><i class="fa fa-refresh fa-spin"></i>&nbsp; Tautulli is connecting to your Plex server...</div>
% if _session['user_group'] == 'admin':
Check the <a href="logs">logs</a> and verify your server connection in the <a href="settings#tab_tabs-plex_media_server">settings</a>.
% endif % endif
</div> </div>
% endif
<br>
</div>
</div> </div>
</div> </div>
% endif % endif
@ -229,7 +220,6 @@
</%def> </%def>
<%def name="javascriptIncludes()"> <%def name="javascriptIncludes()">
<% from plexpy import PLEX_SERVER_UP %>
<script src="${http_root}js/jquery.scrollbar.min.js"></script> <script src="${http_root}js/jquery.scrollbar.min.js"></script>
<script src="${http_root}js/jquery.mousewheel.min.js"></script> <script src="${http_root}js/jquery.mousewheel.min.js"></script>
<script> <script>
@ -259,8 +249,33 @@
} }
}); });
} }
% if _session['user_group'] == 'admin':
var msg_settings = ' Check the <a href="logs">logs</a> and verify your server connection in the <a href="settings#tab_tabs-plex_media_server">settings</a>.';
% else:
var msg_settings = '';
% endif
var error_msg = 'There was an error communicating with your Plex Server.' + msg_settings;
var server_status;
server_status = setInterval(function() {
$.getJSON('server_status', function (data) {
if (data.connected === true) {
clearInterval(server_status);
$('#currentActivity').html('<div id="dashboard-checking-activity" class="text-muted"><i class="fa fa-refresh fa-spin"></i>&nbsp; Checking for activity...</div>');
$('#recentlyAdded').html('<div id="dashboard-checking-recently-added" class="text-muted"><i class="fa fa-refresh fa-spin"></i>&nbsp; Looking for new items...</div>');
activityConnected();
recentlyAddedConnected();
} else if (data.connected === false) {
clearInterval(server_status);
$('#currentActivity').html('<div id="dashboard-no-activity" class="text-muted">' + error_msg + '</div>');
$('#recentlyAdded').html('<div id="dashboard-no-recently-added" class="text-muted">' + error_msg + '</div>');
}
});
}, 1000);
</script> </script>
% if 'current_activity' in config['home_sections'] and PLEX_SERVER_UP: % if 'current_activity' in config['home_sections']:
<script> <script>
var defaultHandler = { var defaultHandler = {
get: function(target, name) { get: function(target, name) {
@ -297,13 +312,8 @@
} }
if (!(current_activity)) { if (!(current_activity)) {
% if _session['user_group'] == 'admin':
var msg_settings = ' Check the <a href="logs">logs</a> and verify your server connection in the <a href="settings#tab_tabs-plex_media_server">settings</a>.';
% else:
var msg_settings = '';
% endif
$('#currentActivityHeader').hide(); $('#currentActivityHeader').hide();
$('#currentActivity').html('<div id="dashboard-no-activity" class="text-muted">There was an error communicating with your Plex Server.' + msg_settings + '</div>'); $('#currentActivity').html('<div id="dashboard-no-activity" class="text-muted">' + error_msg + '</div>');
return return
} }
@ -625,6 +635,7 @@
}); });
} }
function activityConnected() {
getCurrentActivity(); getCurrentActivity();
setInterval(function () { setInterval(function () {
if (!(create_instances.length) && activity_ready) { if (!(create_instances.length) && activity_ready) {
@ -653,6 +664,7 @@
} }
}); });
}, 1000); }, 1000);
}
$('#currentActivity').on('click', '.external_ip-modal', function () { $('#currentActivity').on('click', '.external_ip-modal', function () {
$.get('get_ip_address_details', { $.get('get_ip_address_details', {
@ -876,7 +888,7 @@
getLibraryStats(); getLibraryStats();
</script> </script>
% endif % endif
% if 'recently_added' in config['home_sections'] and PLEX_SERVER_UP: % if 'recently_added' in config['home_sections']:
<script> <script>
function recentlyAdded(recently_added_count, recently_added_type) { function recentlyAdded(recently_added_count, recently_added_type) {
showMsg("Loading recently added items...", true, false, 0); showMsg("Loading recently added items...", true, false, 0);
@ -904,7 +916,9 @@
$('#recently-added-toggle-' + recently_added_type).closest('label').addClass('active'); $('#recently-added-toggle-' + recently_added_type).closest('label').addClass('active');
$('#recently-added-count').val(recently_added_count); $('#recently-added-count').val(recently_added_count);
function recentlyAddedConnected() {
recentlyAdded(recently_added_count, recently_added_type); recentlyAdded(recently_added_count, recently_added_type);
}
function highlightAddedScrollerButton() { function highlightAddedScrollerButton() {
var scroller = $("#recently-added-row-scroller"); var scroller = $("#recently-added-row-scroller");

View file

@ -334,18 +334,6 @@ def initialize(config_file):
logger.error("Unable to write current release to file '%s': %s" % logger.error("Unable to write current release to file '%s': %s" %
(release_file, e)) (release_file, e))
# Get the real PMS urls for SSL and remote access
if CONFIG.PMS_TOKEN and CONFIG.PMS_IP and CONFIG.PMS_PORT:
plextv.get_server_resources()
# Refresh the users list on startup
if CONFIG.PMS_TOKEN and CONFIG.REFRESH_USERS_ON_STARTUP:
users.refresh_users()
# Refresh the libraries list on startup
if CONFIG.PMS_IP and CONFIG.PMS_TOKEN and CONFIG.REFRESH_LIBRARIES_ON_STARTUP:
libraries.refresh_libraries()
# Store the original umask # Store the original umask
UMASK = os.umask(0) UMASK = os.umask(0)
os.umask(UMASK) os.umask(UMASK)
@ -523,6 +511,9 @@ def start():
global _STARTED global _STARTED
if _INITIALIZED: if _INITIALIZED:
# Start refreshes on a separate thread
threading.Thread(target=startup_refresh).start()
global SCHED global SCHED
SCHED = BackgroundScheduler(timezone=pytz.UTC) SCHED = BackgroundScheduler(timezone=pytz.UTC)
activity_handler.ACTIVITY_SCHED = BackgroundScheduler(timezone=pytz.UTC) activity_handler.ACTIVITY_SCHED = BackgroundScheduler(timezone=pytz.UTC)
@ -535,12 +526,13 @@ def start():
notification_handler.start_threads(num_threads=CONFIG.NOTIFICATION_THREADS) notification_handler.start_threads(num_threads=CONFIG.NOTIFICATION_THREADS)
notifiers.check_browser_enabled() notifiers.check_browser_enabled()
# Schedule newsletters
newsletter_handler.NEWSLETTER_SCHED.start()
newsletter_handler.schedule_newsletters()
# Cancel processing exports # Cancel processing exports
exporter.cancel_exports() exporter.cancel_exports()
if CONFIG.FIRST_RUN_COMPLETE:
activity_pinger.connect_server(log=True, startup=True)
if CONFIG.SYSTEM_ANALYTICS: if CONFIG.SYSTEM_ANALYTICS:
global TRACKER global TRACKER
TRACKER = initialize_tracker() TRACKER = initialize_tracker()
@ -554,13 +546,27 @@ def start():
analytics_event(category='system', action='start') analytics_event(category='system', action='start')
# Schedule newsletters
newsletter_handler.NEWSLETTER_SCHED.start()
newsletter_handler.schedule_newsletters()
_STARTED = True _STARTED = True
def startup_refresh():
# Get the real PMS urls for SSL and remote access
if CONFIG.PMS_TOKEN and CONFIG.PMS_IP and CONFIG.PMS_PORT:
plextv.get_server_resources()
# Connect server after server resource is refreshed
if CONFIG.FIRST_RUN_COMPLETE:
activity_pinger.connect_server(log=True, startup=True)
# Refresh the users list on startup
if CONFIG.PMS_TOKEN and CONFIG.REFRESH_USERS_ON_STARTUP:
users.refresh_users()
# Refresh the libraries list on startup
if CONFIG.PMS_IP and CONFIG.PMS_TOKEN and CONFIG.REFRESH_LIBRARIES_ON_STARTUP:
libraries.refresh_libraries()
def sig_handler(signum=None, frame=None): def sig_handler(signum=None, frame=None):
if signum is not None: if signum is not None:
logger.info("Signal %i caught, saving and exiting...", signum) logger.info("Signal %i caught, saving and exiting...", signum)

View file

@ -122,6 +122,7 @@ def add_live_tv_library(refresh=False):
if result and not refresh or not result and refresh: if result and not refresh or not result and refresh:
return return
if not refresh:
logger.info("Tautulli Libraries :: Adding Live TV library to the database.") logger.info("Tautulli Libraries :: Adding Live TV library to the database.")
section_keys = {'server_id': plexpy.CONFIG.PMS_IDENTIFIER, section_keys = {'server_id': plexpy.CONFIG.PMS_IDENTIFIER,

View file

@ -6545,6 +6545,31 @@ class WebInterface(object):
return status return status
@cherrypy.expose
@cherrypy.tools.json_out()
@addtoapi()
def server_status(self, *args, **kwargs):
""" Get the current status of Tautulli's connection to the Plex server.
```
Required parameters:
None
Optional parameters:
None
Returns:
json:
{"result": "success",
"connected": true,
}
```
"""
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
status = {'result': 'success', 'connected': plexpy.PLEX_SERVER_UP}
return status
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
@requireAuth(member_of("admin")) @requireAuth(member_of("admin"))