From a085f0f5382a2947e28058e1e22f21dc31a99146 Mon Sep 17 00:00:00 2001 From: echel0n Date: Tue, 8 Jul 2014 22:42:56 -0700 Subject: [PATCH] Improved and faster nextepisode function, speeds up home page load times. --- gui/slick/interfaces/default/home.tmpl | 4 ++-- sickbeard/tv.py | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gui/slick/interfaces/default/home.tmpl b/gui/slick/interfaces/default/home.tmpl index 03a9c624..34e3f595 100644 --- a/gui/slick/interfaces/default/home.tmpl +++ b/gui/slick/interfaces/default/home.tmpl @@ -237,8 +237,8 @@ $myShowList.sort(lambda x, y: cmp(x.name, y.name)) #set $which_thumb = $layout+"_thumb" - #if len($curEp) != 0: - #set $ldatetime = $network_timezones.parse_date_time($curEp[0].airdate.toordinal(),$curShow.airs,$curShow.network) + #if $curEp: + #set $ldatetime = $network_timezones.parse_date_time($curEp.airdate.toordinal(),$curShow.airs,$curShow.network)
$sbdatetime.sbdatetime.sbfdate($ldatetime)
$time.mktime($ldatetime.timetuple()) #else: diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 57ac05bb..c1e15378 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -979,11 +979,8 @@ class TVShow(object): logger.log(str(self.indexerid) + ": Finding the episode which airs next", logger.DEBUG) myDB = db.DBConnection() - innerQuery = "SELECT airdate FROM tv_episodes WHERE showid = ? AND airdate >= ? AND status in (?,?) ORDER BY airdate ASC LIMIT 1" - innerParams = [self.indexerid, datetime.date.today().toordinal(), UNAIRED, WANTED] - query = "SELECT * FROM tv_episodes WHERE showid = ? AND airdate >= ? AND airdate <= (" + innerQuery + ") and status in (?,?)" - params = [self.indexerid, datetime.date.today().toordinal()] + innerParams + [UNAIRED, WANTED] - sqlResults = myDB.select(query, params) + sqlResults = myDB.select("SELECT airdate, season, episode FROM tv_episodes WHERE showid = ? AND airdate >= ? AND status in (?,?) ORDER BY airdate ASC LIMIT 1", + [self.indexerid, datetime.date.today().toordinal(), UNAIRED, WANTED]) if sqlResults == None or len(sqlResults) == 0: logger.log(str(self.indexerid) + u": No episode found... need to implement a show status", @@ -992,11 +989,8 @@ class TVShow(object): else: logger.log(str(self.indexerid) + u": Found episode " + str(sqlResults[0]["season"]) + "x" + str( sqlResults[0]["episode"]), logger.DEBUG) - foundEps = [] - for sqlEp in sqlResults: - curEp = self.getEpisode(int(sqlEp["season"]), int(sqlEp["episode"])) - foundEps.append(curEp) - return foundEps + curEp = self.getEpisode(int(sqlResults[0]["season"]), int(sqlResults[0]["episode"])) + return curEp def deleteShow(self):