mirror of
https://github.com/morpheus65535/bazarr
synced 2025-02-20 13:07:03 +00:00
Performance improvement to event emission from backend and handling from frontend.
This commit is contained in:
parent
e2b1726c87
commit
f7f30a4157
4 changed files with 55 additions and 21 deletions
|
@ -77,7 +77,7 @@ class Restart(Resource):
|
||||||
webserver.restart()
|
webserver.restart()
|
||||||
|
|
||||||
|
|
||||||
class Badges(Resource):
|
class BadgesSeries(Resource):
|
||||||
@authenticate
|
@authenticate
|
||||||
def get(self):
|
def get(self):
|
||||||
missing_episodes = database.execute("SELECT table_shows.tags, table_episodes.monitored, table_shows.seriesType "
|
missing_episodes = database.execute("SELECT table_shows.tags, table_episodes.monitored, table_shows.seriesType "
|
||||||
|
@ -87,14 +87,30 @@ class Badges(Resource):
|
||||||
missing_episodes = filter_exclusions(missing_episodes, 'series')
|
missing_episodes = filter_exclusions(missing_episodes, 'series')
|
||||||
missing_episodes = len(missing_episodes)
|
missing_episodes = len(missing_episodes)
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"missing_episodes": missing_episodes
|
||||||
|
}
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
|
||||||
|
class BadgesMovies(Resource):
|
||||||
|
@authenticate
|
||||||
|
def get(self):
|
||||||
missing_movies = database.execute("SELECT tags, monitored FROM table_movies WHERE missing_subtitles is not "
|
missing_movies = database.execute("SELECT tags, monitored FROM table_movies WHERE missing_subtitles is not "
|
||||||
"null AND missing_subtitles != '[]'")
|
"null AND missing_subtitles != '[]'")
|
||||||
missing_movies = filter_exclusions(missing_movies, 'movie')
|
missing_movies = filter_exclusions(missing_movies, 'movie')
|
||||||
missing_movies = len(missing_movies)
|
missing_movies = len(missing_movies)
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"missing_episodes": missing_episodes,
|
"missing_movies": missing_movies
|
||||||
"missing_movies": missing_movies,
|
}
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
|
||||||
|
class BadgesProviders(Resource):
|
||||||
|
@authenticate
|
||||||
|
def get(self):
|
||||||
|
result = {
|
||||||
"throttled_providers": len(eval(str(settings.general.throtteled_providers)))
|
"throttled_providers": len(eval(str(settings.general.throtteled_providers)))
|
||||||
}
|
}
|
||||||
return jsonify(result)
|
return jsonify(result)
|
||||||
|
@ -1796,7 +1812,9 @@ class BrowseRadarrFS(Resource):
|
||||||
api.add_resource(Shutdown, '/shutdown')
|
api.add_resource(Shutdown, '/shutdown')
|
||||||
api.add_resource(Restart, '/restart')
|
api.add_resource(Restart, '/restart')
|
||||||
|
|
||||||
api.add_resource(Badges, '/badges')
|
api.add_resource(BadgesSeries, '/badges_series')
|
||||||
|
api.add_resource(BadgesMovies, '/badges_movies')
|
||||||
|
api.add_resource(BadgesProviders, '/badges_providers')
|
||||||
api.add_resource(Languages, '/languages')
|
api.add_resource(Languages, '/languages')
|
||||||
api.add_resource(Notifications, '/notifications')
|
api.add_resource(Notifications, '/notifications')
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,7 @@ def provider_throttle(name, exception):
|
||||||
logging.info("Throttling %s for %s, until %s, because of: %s. Exception info: %r", name,
|
logging.info("Throttling %s for %s, until %s, because of: %s. Exception info: %r", name,
|
||||||
throttle_description, throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, exception.args[0]
|
throttle_description, throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, exception.args[0]
|
||||||
if exception.args else None)
|
if exception.args else None)
|
||||||
|
update_throttled_provider()
|
||||||
|
|
||||||
|
|
||||||
def throttled_count(name):
|
def throttled_count(name):
|
||||||
|
@ -255,7 +256,7 @@ def update_throttled_provider():
|
||||||
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
|
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
|
||||||
settings.write(handle)
|
settings.write(handle)
|
||||||
|
|
||||||
event_stream(type='badges')
|
event_stream(type='badges_providers')
|
||||||
|
|
||||||
|
|
||||||
def list_throttled_providers():
|
def list_throttled_providers():
|
||||||
|
|
|
@ -236,7 +236,7 @@ def list_missing_subtitles(no=None, epno=None, send_event=True):
|
||||||
if send_event:
|
if send_event:
|
||||||
event_stream(type='episode', action='update', series=missing_subtitles_item[2],
|
event_stream(type='episode', action='update', series=missing_subtitles_item[2],
|
||||||
episode=missing_subtitles_item[1])
|
episode=missing_subtitles_item[1])
|
||||||
event_stream(type='badges')
|
event_stream(type='badges_series')
|
||||||
|
|
||||||
|
|
||||||
def list_missing_subtitles_movies(no=None, send_event=True):
|
def list_missing_subtitles_movies(no=None, send_event=True):
|
||||||
|
@ -297,7 +297,7 @@ def list_missing_subtitles_movies(no=None, send_event=True):
|
||||||
|
|
||||||
if send_event:
|
if send_event:
|
||||||
event_stream(type='movie', action='update', movie=missing_subtitles_item[1])
|
event_stream(type='movie', action='update', movie=missing_subtitles_item[1])
|
||||||
event_stream(type='badges')
|
event_stream(type='badges_movies')
|
||||||
|
|
||||||
|
|
||||||
def series_full_scan_subtitles():
|
def series_full_scan_subtitles():
|
||||||
|
|
|
@ -374,7 +374,9 @@
|
||||||
<script>
|
<script>
|
||||||
{% if not request.endpoint == 'login_page' %}
|
{% if not request.endpoint == 'login_page' %}
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
BadgesAjax();
|
BadgesAjax('series');
|
||||||
|
BadgesAjax('movies');
|
||||||
|
BadgesAjax('providers');
|
||||||
|
|
||||||
$(window).on( 'ready orientationchange resize', function() {
|
$(window).on( 'ready orientationchange resize', function() {
|
||||||
adjustResponsiveUI();
|
adjustResponsiveUI();
|
||||||
|
@ -412,30 +414,43 @@
|
||||||
|
|
||||||
events.on('event', function (event) {
|
events.on('event', function (event) {
|
||||||
var event_json_badges = JSON.parse(event);
|
var event_json_badges = JSON.parse(event);
|
||||||
if (event_json_badges.type === 'badges') {
|
if (event_json_badges.type === 'badges_series') {
|
||||||
BadgesAjax();
|
BadgesAjax('series');
|
||||||
|
} else if (event_json_badges.type === 'badges_movies') {
|
||||||
|
BadgesAjax('movies');
|
||||||
|
} else if (event_json_badges.type === 'badges_providers') {
|
||||||
|
BadgesAjax('providers');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function BadgesAjax() {
|
function BadgesAjax(type) {
|
||||||
|
if (type=='series') {
|
||||||
|
var url = "{{url_for('api.badgesseries')}}";
|
||||||
|
} else if (type=='movies') {
|
||||||
|
var url = "{{url_for('api.badgesmovies')}}";
|
||||||
|
} else if (type=='providers') {
|
||||||
|
var url = "{{url_for('api.badgesproviders')}}";
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "{{url_for('api.badges')}}",
|
url: url,
|
||||||
async: true,
|
async: true,
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data['throttled_providers']) {
|
if (data['throttled_providers'] == 0) {
|
||||||
$('.throttled_providers_count').html('<span class="badge badge-secondary">' + data['throttled_providers'] + '</span>');
|
|
||||||
} else {
|
|
||||||
$('.throttled_providers_count').html('');
|
$('.throttled_providers_count').html('');
|
||||||
|
} else if (data['throttled_providers'] > 0) {
|
||||||
|
$('.throttled_providers_count').html('<span class="badge badge-secondary">' + data['throttled_providers'] + '</span>');
|
||||||
}
|
}
|
||||||
if (data['missing_episodes']) {
|
if (data['missing_episodes'] == 0) {
|
||||||
$('.wanted_series_badge').html('<span class="badge badge-secondary">' + data['missing_episodes'] + '</span>');
|
|
||||||
} else {
|
|
||||||
$('.wanted_series_badge').html('');
|
$('.wanted_series_badge').html('');
|
||||||
|
} else if (data['missing_episodes'] > 0) {
|
||||||
|
$('.wanted_series_badge').html('<span class="badge badge-secondary">' + data['missing_episodes'] + '</span>');
|
||||||
}
|
}
|
||||||
if (data['missing_movies']) {
|
if (data['missing_movies'] == 0) {
|
||||||
$('.wanted_movies_badge').html('<span class="badge badge-secondary">' + data['missing_movies'] + '</span>');
|
|
||||||
} else {
|
|
||||||
$('.wanted_movies_badge').html('');
|
$('.wanted_movies_badge').html('');
|
||||||
|
} else if (data['missing_movies'] > 0) {
|
||||||
|
$('.wanted_movies_badge').html('<span class="badge badge-secondary">' + data['missing_movies'] + '</span>');
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue