Commit 940d091a authored by echel0n's avatar echel0n

Revert "Refactored TVShow and TVEpisode database models to use select instead...

Revert "Refactored TVShow and TVEpisode database models to use select instead of joined for lazy loading relationships."

This reverts commit 7bff6d73
parent 2afbbf6f
......@@ -20,8 +20,9 @@
# ##############################################################################
import threading
from tornado import gen
import sickrage
from sickrage.core.databases.main import MainDB
from sickrage.core.databases.cache import CacheDB
from sickrage.core.media.util import showImage
from sickrage.core.tv.show.helpers import find_show, get_show_list
......@@ -65,37 +66,38 @@ class QuicksearchCache(object):
@CacheDB.with_session
def add_show(self, indexer_id, session=None):
show = find_show(indexer_id)
if indexer_id not in self.cache['shows']:
with MainDB.session() as maindb_session:
show = find_show(indexer_id, session=maindb_session)
sickrage.app.log.debug("Adding show {} to QuickSearch cache".format(show.name))
qs_data = {
'category': 'shows',
'showid': indexer_id,
'seasons': len(set([e.season for e in show.episodes if e.season != 0])),
'name': show.name,
'img': sickrage.app.config.web_root + showImage(indexer_id, 'poster_thumb').url
sickrage.app.log.debug("Adding show {} to QuickSearch cache".format(show.name))
qsData = {
'category': 'shows',
'showid': indexer_id,
'seasons': len(set([e.season for e in show.episodes if e.season != 0])),
'name': show.name,
'img': sickrage.app.config.web_root + showImage(indexer_id, 'poster_thumb').url
}
self.cache['shows'][indexer_id] = qsData
session.add(CacheDB.QuickSearchShow(**qsData))
sql_t = []
for e in show.episodes:
qsData = {
'category': 'episodes',
'showid': e.showid,
'episodeid': e.indexer_id,
'season': e.season,
'episode': e.episode,
'name': e.name,
'showname': show.name,
'img': sickrage.app.config.web_root + showImage(e.showid, 'poster_thumb').url
}
self.cache['shows'][indexer_id] = qs_data
session.add(CacheDB.QuickSearchShow(**qs_data))
sql_t = []
for e in show.episodes:
qs_data = {
'category': 'episodes',
'showid': e.showid,
'episodeid': e.indexer_id,
'season': e.season,
'episode': e.episode,
'name': e.name,
'showname': show.name,
'img': sickrage.app.config.web_root + showImage(e.showid, 'poster_thumb').url
}
sql_t.append(qs_data)
self.cache['episodes'][e.indexer_id] = qs_data
sql_t.append(qsData)
self.cache['episodes'][e.indexer_id] = qsData
session.bulk_insert_mappings(CacheDB.QuickSearchEpisode, sql_t)
......
......@@ -81,7 +81,7 @@ class TVEpisode(MainDBBase):
version = Column(Integer, default=-1)
release_group = Column(Text, default='')
show = relationship('TVShow', uselist=False, backref='tv_episodes')
show = relationship('TVShow', uselist=False, backref='tv_episodes', lazy='joined')
def __init__(self, **kwargs):
super(TVEpisode, self).__init__(**kwargs)
......
......@@ -89,8 +89,8 @@ class TVShow(MainDBBase):
last_backlog_search = Column(Integer, default=datetime.datetime.now().toordinal())
last_proper_search = Column(Integer, default=datetime.datetime.now().toordinal())
episodes = relationship('TVEpisode', uselist=True, backref='tv_shows')
imdb_info = relationship('IMDbInfo', uselist=False, backref='tv_shows')
episodes = relationship('TVEpisode', uselist=True, backref='tv_shows', lazy='joined')
imdb_info = relationship('IMDbInfo', uselist=False, backref='tv_shows', lazy='joined')
@property
def is_anime(self):
......
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