1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2025-03-01 00:55:52 +00:00

Removed hardcoded table relations in joins.

This commit is contained in:
morpheus65535 2021-09-12 23:28:11 -04:00
parent 438392c1fd
commit c98c0d3811
3 changed files with 28 additions and 28 deletions

View file

@ -290,7 +290,7 @@ class Badges(Resource):
missing_episodes = TableEpisodes.select(TableShows.tags, missing_episodes = TableEpisodes.select(TableShows.tags,
TableShows.seriesType, TableShows.seriesType,
TableEpisodes.monitored)\ TableEpisodes.monitored)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(reduce(operator.and_, episodes_conditions))\ .where(reduce(operator.and_, episodes_conditions))\
.count() .count()
@ -639,7 +639,7 @@ class Series(Resource):
episodeMissingCount = TableEpisodes.select(TableShows.tags, episodeMissingCount = TableEpisodes.select(TableShows.tags,
TableEpisodes.monitored, TableEpisodes.monitored,
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(reduce(operator.and_, episodes_missing_conditions))\ .where(reduce(operator.and_, episodes_missing_conditions))\
.count() .count()
item.update({"episodeMissingCount": episodeMissingCount}) item.update({"episodeMissingCount": episodeMissingCount})
@ -648,7 +648,7 @@ class Series(Resource):
episodeFileCount = TableEpisodes.select(TableShows.tags, episodeFileCount = TableEpisodes.select(TableShows.tags,
TableEpisodes.monitored, TableEpisodes.monitored,
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(TableEpisodes.seriesId == item['seriesId'])\ .where(TableEpisodes.seriesId == item['seriesId'])\
.count() .count()
item.update({"episodeFileCount": episodeFileCount}) item.update({"episodeFileCount": episodeFileCount})
@ -1358,7 +1358,7 @@ class ProviderEpisodes(Resource):
episodeInfo = TableEpisodes.select(TableEpisodes.title, episodeInfo = TableEpisodes.select(TableEpisodes.title,
TableEpisodes.path, TableEpisodes.path,
TableShows.profileId) \ TableShows.profileId) \
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(TableEpisodes.episodeId == episodeId) \ .where(TableEpisodes.episodeId == episodeId) \
.dicts() \ .dicts() \
.get() .get()
@ -1460,8 +1460,8 @@ class EpisodesHistory(Resource):
TableShows.tags, TableShows.tags,
TableEpisodes.monitored, TableEpisodes.monitored,
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableEpisodes, on=(TableHistory.episodeId == TableEpisodes.episodeId))\ .join(TableEpisodes) \
.join(TableShows, on=(TableHistory.seriesId == TableShows.seriesId))\ .join(TableShows) \
.where(reduce(operator.and_, upgradable_episodes_conditions))\ .where(reduce(operator.and_, upgradable_episodes_conditions))\
.group_by(TableHistory.video_path)\ .group_by(TableHistory.video_path)\
.dicts() .dicts()
@ -1498,8 +1498,8 @@ class EpisodesHistory(Resource):
TableHistory.episodeId, TableHistory.episodeId,
TableHistory.provider, TableHistory.provider,
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableShows, on=(TableHistory.seriesId == TableShows.seriesId))\ .join(TableEpisodes) \
.join(TableEpisodes, on=(TableHistory.episodeId == TableEpisodes.episodeId))\ .join(TableShows) \
.where(query_condition)\ .where(query_condition)\
.order_by(TableHistory.timestamp.desc())\ .order_by(TableHistory.timestamp.desc())\
.limit(length)\ .limit(length)\
@ -1542,7 +1542,7 @@ class EpisodesHistory(Resource):
break break
count = TableHistory.select()\ count = TableHistory.select()\
.join(TableEpisodes, on=(TableHistory.episodeId == TableEpisodes.episodeId))\ .join(TableEpisodes)\
.where(TableEpisodes.title is not None).count() .where(TableEpisodes.title is not None).count()
return jsonify(data=episode_history, total=count) return jsonify(data=episode_history, total=count)
@ -1576,7 +1576,7 @@ class MoviesHistory(Resource):
TableHistoryMovie.score, TableHistoryMovie.score,
TableMovies.tags, TableMovies.tags,
TableMovies.monitored)\ TableMovies.monitored)\
.join(TableMovies, on=(TableHistoryMovie.movieId == TableMovies.movieId))\ .join(TableMovies)\
.where(reduce(operator.and_, upgradable_movies_conditions))\ .where(reduce(operator.and_, upgradable_movies_conditions))\
.group_by(TableHistoryMovie.video_path)\ .group_by(TableHistoryMovie.video_path)\
.dicts() .dicts()
@ -1611,7 +1611,7 @@ class MoviesHistory(Resource):
TableHistoryMovie.subs_id, TableHistoryMovie.subs_id,
TableHistoryMovie.provider, TableHistoryMovie.provider,
TableHistoryMovie.subtitles_path)\ TableHistoryMovie.subtitles_path)\
.join(TableMovies, on=(TableHistoryMovie.movieId == TableMovies.movieId))\ .join(TableMovies)\
.where(query_condition)\ .where(query_condition)\
.order_by(TableHistoryMovie.timestamp.desc())\ .order_by(TableHistoryMovie.timestamp.desc())\
.limit(length)\ .limit(length)\
@ -1653,7 +1653,7 @@ class MoviesHistory(Resource):
break break
count = TableHistoryMovie.select()\ count = TableHistoryMovie.select()\
.join(TableMovies, on=(TableHistoryMovie.movieId == TableMovies.movieId))\ .join(TableMovies)\
.where(TableMovies.title is not None)\ .where(TableMovies.title is not None)\
.count() .count()
@ -1753,7 +1753,7 @@ class EpisodesWanted(Resource):
TableShows.tags, TableShows.tags,
TableEpisodes.failedAttempts, TableEpisodes.failedAttempts,
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(wanted_condition)\ .where(wanted_condition)\
.dicts() .dicts()
else: else:
@ -1769,7 +1769,7 @@ class EpisodesWanted(Resource):
TableShows.tags, TableShows.tags,
TableEpisodes.failedAttempts, TableEpisodes.failedAttempts,
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(wanted_condition)\ .where(wanted_condition)\
.order_by(TableEpisodes.episodeId.desc())\ .order_by(TableEpisodes.episodeId.desc())\
.limit(length)\ .limit(length)\
@ -1785,7 +1785,7 @@ class EpisodesWanted(Resource):
count = TableEpisodes.select(TableShows.tags, count = TableEpisodes.select(TableShows.tags,
TableShows.seriesType, TableShows.seriesType,
TableEpisodes.monitored)\ TableEpisodes.monitored)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(reduce(operator.and_, count_conditions))\ .where(reduce(operator.and_, count_conditions))\
.count() .count()
@ -1859,8 +1859,8 @@ class EpisodesBlacklist(Resource):
TableBlacklist.subs_id, TableBlacklist.subs_id,
TableBlacklist.language, TableBlacklist.language,
TableBlacklist.timestamp)\ TableBlacklist.timestamp)\
.join(TableEpisodes, on=(TableBlacklist.episode_id == TableEpisodes.episodeId))\ .join(TableEpisodes)\
.join(TableShows, on=(TableBlacklist.series_id == TableShows.seriesId))\ .join(TableShows)\
.order_by(TableBlacklist.timestamp.desc())\ .order_by(TableBlacklist.timestamp.desc())\
.limit(length)\ .limit(length)\
.offset(start)\ .offset(start)\
@ -1935,7 +1935,7 @@ class MoviesBlacklist(Resource):
TableBlacklistMovie.subs_id, TableBlacklistMovie.subs_id,
TableBlacklistMovie.language, TableBlacklistMovie.language,
TableBlacklistMovie.timestamp)\ TableBlacklistMovie.timestamp)\
.join(TableMovies, on=(TableBlacklistMovie.movie_id == TableMovies.movieId))\ .join(TableMovies)\
.order_by(TableBlacklistMovie.timestamp.desc())\ .order_by(TableBlacklistMovie.timestamp.desc())\
.limit(length)\ .limit(length)\
.offset(start)\ .offset(start)\
@ -2128,7 +2128,7 @@ class WebHooksPlex(Resource):
return '', 404 return '', 404
else: else:
episodeId = TableEpisodes.select(TableEpisodes.episodeId) \ episodeId = TableEpisodes.select(TableEpisodes.episodeId) \
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId)) \ .join(TableShows) \
.where(TableShows.imdbId == series_imdb_id, .where(TableShows.imdbId == series_imdb_id,
TableEpisodes.season == season, TableEpisodes.season == season,
TableEpisodes.episode == episode) \ TableEpisodes.episode == episode) \

View file

@ -704,7 +704,7 @@ def series_download_subtitles(no):
TableEpisodes.season, TableEpisodes.season,
TableEpisodes.episode, TableEpisodes.episode,
TableEpisodes.title.alias('episodeTitle'))\ TableEpisodes.title.alias('episodeTitle'))\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(reduce(operator.and_, conditions))\ .where(reduce(operator.and_, conditions))\
.dicts() .dicts()
if not episodes_details: if not episodes_details:
@ -793,7 +793,7 @@ def episode_download_subtitles(no, send_progress=False):
TableEpisodes.title.alias('episodeTitle'), TableEpisodes.title.alias('episodeTitle'),
TableEpisodes.season, TableEpisodes.season,
TableEpisodes.episode)\ TableEpisodes.episode)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(reduce(operator.and_, conditions))\ .where(reduce(operator.and_, conditions))\
.dicts() .dicts()
if not episodes_details: if not episodes_details:
@ -954,7 +954,7 @@ def wanted_download_subtitles(episode_id):
TableEpisodes.audio_language, TableEpisodes.audio_language,
TableEpisodes.failedAttempts, TableEpisodes.failedAttempts,
TableShows.title)\ TableShows.title)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where((TableEpisodes.episodeId == episode_id))\ .where((TableEpisodes.episodeId == episode_id))\
.dicts() .dicts()
episodes_details = list(episodes_details) episodes_details = list(episodes_details)
@ -1124,7 +1124,7 @@ def wanted_search_missing_subtitles_series():
TableEpisodes.episode, TableEpisodes.episode,
TableEpisodes.title.alias('episodeTitle'), TableEpisodes.title.alias('episodeTitle'),
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(reduce(operator.and_, conditions))\ .where(reduce(operator.and_, conditions))\
.dicts() .dicts()
episodes = list(episodes) episodes = list(episodes)
@ -1223,7 +1223,7 @@ def refine_from_db(path, video):
TableEpisodes.audio_codec, TableEpisodes.audio_codec,
TableEpisodes.path, TableEpisodes.path,
TableShows.imdbId)\ TableShows.imdbId)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where((TableEpisodes.path == path))\ .where((TableEpisodes.path == path))\
.dicts() .dicts()
@ -1365,8 +1365,8 @@ def upgrade_subtitles():
TableEpisodes.episode, TableEpisodes.episode,
TableShows.title.alias('seriesTitle'), TableShows.title.alias('seriesTitle'),
TableShows.seriesType)\ TableShows.seriesType)\
.join(TableShows, on=(TableHistory.seriesId == TableShows.seriesId))\ .join(TableEpisodes) \
.join(TableEpisodes, on=(TableHistory.episodeId == TableEpisodes.episodeId))\ .join(TableShows) \
.where(reduce(operator.and_, upgradable_episodes_conditions))\ .where(reduce(operator.and_, upgradable_episodes_conditions))\
.group_by(TableHistory.video_path, TableHistory.language)\ .group_by(TableHistory.video_path, TableHistory.language)\
.dicts() .dicts()
@ -1406,7 +1406,7 @@ def upgrade_subtitles():
TableMovies.tags, TableMovies.tags,
TableMovies.movieId, TableMovies.movieId,
TableMovies.title)\ TableMovies.title)\
.join(TableMovies, on=(TableHistoryMovie.movieId == TableMovies.movieId))\ .join(TableMovies)\
.where(reduce(operator.and_, upgradable_movies_conditions))\ .where(reduce(operator.and_, upgradable_movies_conditions))\
.group_by(TableHistoryMovie.video_path, TableHistoryMovie.language)\ .group_by(TableHistoryMovie.video_path, TableHistoryMovie.language)\
.dicts() .dicts()

View file

@ -241,7 +241,7 @@ def list_missing_subtitles(no=None, epno=None, send_event=True):
TableEpisodes.subtitles, TableEpisodes.subtitles,
TableShows.profileId, TableShows.profileId,
TableEpisodes.audio_language)\ TableEpisodes.audio_language)\
.join(TableShows, on=(TableEpisodes.seriesId == TableShows.seriesId))\ .join(TableShows)\
.where(episodes_subtitles_clause)\ .where(episodes_subtitles_clause)\
.dicts() .dicts()
if isinstance(episodes_subtitles, str): if isinstance(episodes_subtitles, str):