Commit 77cbb467 authored by echel0n's avatar echel0n

Refactored shows cache to populate after database init.

Refactored TVShow class to use get_episode instead of calling TVEpisode class directly when populating shows episode cache.
Removed type hints for now, will make a project of adding type hints later on.
Refactored ajax calls for episode search status to always pass a series ID.
parent 1e290d8b
......@@ -287,6 +287,9 @@ class Core(object):
self.log.info("Performing cleanup on {} database".format(db.name))
db.cleanup()
# load shows
self.load_shows()
# user agent
if self.config.random_user_agent:
self.user_agent = UserAgent().random
......@@ -546,7 +549,6 @@ class Core(object):
self.config.web_host, self.config.web_port, self.config.web_root))
# start io_loop
self.io_loop.add_callback(self.load_shows)
self.io_loop.add_callback(started)
self.io_loop.start()
......
......@@ -34,7 +34,7 @@ from sickrage.core.tv.show.helpers import find_show, get_show_list
from sickrage.indexers import IndexerApi
def set_episode_to_wanted(show, s: int, e: int):
def set_episode_to_wanted(show, s, e):
"""
Sets an episode to wanted, only if it is currently skipped
"""
......
......@@ -345,7 +345,7 @@ class TVShow(object):
def episodes(self):
if not self._episodes:
query = self.db_session.query(MainDB.TVShow).filter_by(indexer_id=self.indexer_id, indexer=self.indexer).one()
[self._episodes.update({(x.season, x.episode): TVEpisode(x.showid, x.indexer, x.season, x.episode)}) for x in query.episodes]
[self._episodes.update({(x.season, x.episode): self.get_episode(x.season, x.episode)}) for x in query.episodes]
return self._episodes.values()
@property
......
......@@ -24,7 +24,6 @@ import sickrage
from sickrage.core.common import Quality, get_quality_string, WANTED, UNAIRED, timeFormat, dateFormat
from sickrage.core.helpers.srdatetime import SRDateTime
from sickrage.core.tv.show.helpers import get_show_list
from sickrage.core.databases.main import MainDB
class ComingEpisodes:
......@@ -103,8 +102,7 @@ class ComingEpisodes:
if today <= e.airdate < next_week and e.status not in qualities_list:
results += result(s, e)
if e.showid not in [int(r['showid']) for r in results] \
and e.airdate >= next_week and e.status \
if e.showid not in [int(r['showid']) for r in results] and e.airdate >= next_week and e.status \
not in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER:
results += result(s, e)
......
......@@ -22,17 +22,17 @@
import sickrage
def find_show(indexer_id: int, indexer: int = 1):
def find_show(indexer_id, indexer=1):
return sickrage.app.shows.get((int(indexer_id), int(indexer)), None)
def find_show_by_name(term: str):
def find_show_by_name(term):
for show in get_show_list():
if term in show.name:
return show
def find_show_by_location(location: str):
def find_show_by_location(location):
for show in get_show_list():
if show.location == location:
return show
......
......@@ -1303,7 +1303,7 @@ class SearchEpisodeHandler(BaseHandler, ABC):
class GetManualSearchStatusHandler(BaseHandler, ABC):
@authenticated
def get(self, *args, **kwargs):
show = self.get_argument('show', None)
show = self.get_argument('show')
# Queued Searches
search_status = 'Queued'
......@@ -1334,7 +1334,7 @@ class GetManualSearchStatusHandler(BaseHandler, ABC):
return self.write(json_encode({'episodes': episodes}))
def get_episodes(self, show_id: int, items: list, search_status: str):
def get_episodes(self, show_id, items, search_status):
results = []
if not show_id:
......
......@@ -775,31 +775,34 @@ $(document).ready(function ($) {
},
checkManualSearches: function () {
var pollInterval = 5000;
var showId = $('#showID').val();
var url = showId !== undefined ? SICKRAGE.ajax_search.searchStatusUrl + '?show=' + showId : SICKRAGE.ajax_search.searchStatusUrl;
$.ajax({
url: url,
success: function (data) {
if (data.episodes) {
pollInterval = 5000;
} else {
pollInterval = 15000;
}
const showId = $('#showID').val();
SICKRAGE.ajax_search.updateImages(data);
//cleanupManualSearches(data);
},
error: function () {
pollInterval = 30000;
},
type: "GET",
dataType: "json",
complete: function () {
setTimeout(SICKRAGE.ajax_search.checkManualSearches, pollInterval);
},
timeout: 15000 // timeout every 15 secs
});
if (showId !== undefined) {
let pollInterval = 5000;
$.ajax({
url: SICKRAGE.ajax_search.searchStatusUrl + `?show=${showId}`,
success: function (data) {
if (data.episodes) {
pollInterval = 5000;
} else {
pollInterval = 15000;
}
SICKRAGE.ajax_search.updateImages(data);
//cleanupManualSearches(data);
},
error: function () {
pollInterval = 30000;
},
type: "GET",
dataType: "json",
complete: function () {
setTimeout(SICKRAGE.ajax_search.checkManualSearches, pollInterval);
},
timeout: 15000 // timeout every 15 secs
});
}
},
ajaxEpSearch: function (options) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment