Commit 5a6f56e8 authored by echel0n's avatar echel0n

Fixed issue with TV episodes cache, added code to refresh cache after modifying it.

parent 5f87e441
......@@ -68,7 +68,7 @@ class TVEpisode(object):
episodes = self.show.episodes()
episodes.append(self)
self.show.episodes.set(episodes)
self.show.refresh_episodes()
self.populate_episode(season, episode)
# self.checkForMetaFiles()
......@@ -289,11 +289,15 @@ class TVEpisode(object):
session.commit()
episodes = self.show.episodes()
index = next((i for i, x in enumerate(episodes) if
x.showid == self.showid and x.indexer == self.indexer and x.season == self.season and x.episode == self.episode))
episodes[index] = self
self.show.episodes.set(episodes)
try:
episodes = self.show.episodes()
index = next((i for i, x in enumerate(episodes) if
x.showid == self.showid and x.indexer == self.indexer and x.season == self.season and x.episode == self.episode))
episodes[index] = self
self.show.episodes.set(episodes)
self.show.refresh_episodes()
except StopIteration:
pass
def delete(self):
with sickrage.app.main_db.session() as session:
......@@ -305,6 +309,7 @@ class TVEpisode(object):
self.show.episodes.set([x for x in self.show.episodes() if
x.showid != self.showid and x.indexer != self.indexer and x.season != self.season and x.episode != self.episode])
self.show.refresh_episodes()
def refresh_subtitles(self):
"""Look for subtitles files and refresh the subtitles property"""
......
......@@ -531,8 +531,13 @@ class TVShow(object):
session.query(MainDB.TVShow).filter_by(indexer_id=self.indexer_id, indexer=self.indexer).delete()
session.commit()
def flush_episodes(self):
def refresh_episodes(self):
self.episodes.refresh(self)
def flush_episodes(self, refresh=True):
self.episodes.set([x for x in self.episodes() if x.showid != self.indexer_id and x.indexer != self.indexer])
if refresh:
self.refresh_episodes()
def load_from_indexer(self, cache=True, tvapi=None):
if self.indexer is not INDEXER_TVRAGE:
......@@ -648,6 +653,8 @@ class TVShow(object):
tv_episode = TVEpisode(showid=self.indexer_id, indexer=self.indexer, season=season, episode=episode)
episodes.append(tv_episode)
self.episodes.set(episodes)
finally:
self.refresh_episodes()
return tv_episode
except orm.exc.MultipleResultsFound:
......@@ -975,7 +982,7 @@ class TVShow(object):
self.save()
# remove episodes from show episode cache
self.flush_episodes()
self.flush_episodes(refresh=False)
# remove from show cache
del sickrage.app.shows[(self.indexer_id, self.indexer)]
......
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