Commit 7bff6d73 authored by echel0n's avatar echel0n

Refactored TVShow and TVEpisode database models to use select instead of...

Refactored TVShow and TVEpisode database models to use select instead of joined for lazy loading relationships.
parent 84a5ed4b
......@@ -20,9 +20,8 @@
# ##############################################################################
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
......@@ -66,38 +65,37 @@ 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']:
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
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
}
sql_t.append(qsData)
self.cache['episodes'][e.indexer_id] = qsData
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
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', lazy='joined')
show = relationship('TVShow', uselist=False, backref='tv_episodes')
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', lazy='joined')
imdb_info = relationship('IMDbInfo', uselist=False, backref='tv_shows', lazy='joined')
episodes = relationship('TVEpisode', uselist=True, backref='tv_shows')
imdb_info = relationship('IMDbInfo', uselist=False, backref='tv_shows')
@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