Browse Source

Make sure to not query db when there aren't any ids

pull/2133/head
Ruud 12 years ago
parent
commit
226cf6fc38
  1. 2
      couchpotato/core/media/movie/_base/main.py
  2. 82
      couchpotato/core/plugins/dashboard/main.py

2
couchpotato/core/media/movie/_base/main.py

@ -213,6 +213,8 @@ class MovieBase(MovieTypeBase):
q = q.filter(or_(*filter_or))
total_count = q.count()
if total_count == 0:
return 0, []
if order == 'release_order':
q = q.order_by(desc(Release.last_edit))

82
couchpotato/core/plugins/dashboard/main.py

@ -61,56 +61,60 @@ class Dashboard(Plugin):
.order_by(asc(LibraryTitle.simple_title))
active = q.all()
movies = []
# Do the shuffle
if random:
rndm.shuffle(active)
if len(active) > 0:
movie_ids = []
for movie in active:
movie_id, profile_id, info, year = movie
# Do the shuffle
if random:
rndm.shuffle(active)
pp = profile_pre.get(profile_id)
if not pp: continue
movie_ids = []
for movie in active:
movie_id, profile_id, info, year = movie
eta = info.get('release_date', {}) or {}
coming_soon = False
pp = profile_pre.get(profile_id)
if not pp: continue
# Theater quality
if pp.get('theater') and fireEvent('movie.searcher.could_be_released', True, eta, year, single = True):
coming_soon = True
elif pp.get('dvd') and fireEvent('movie.searcher.could_be_released', False, eta, year, single = True):
coming_soon = True
eta = info.get('release_date', {}) or {}
coming_soon = False
if coming_soon:
# Theater quality
if pp.get('theater') and fireEvent('movie.searcher.could_be_released', True, eta, year, single = True):
coming_soon = True
elif pp.get('dvd') and fireEvent('movie.searcher.could_be_released', False, eta, year, single = True):
coming_soon = True
# Don't list older movies
if ((not late and (not eta.get('dvd') and not eta.get('theater') or eta.get('dvd') and eta.get('dvd') > (now - 2419200))) or
(late and (eta.get('dvd', 0) > 0 or eta.get('theater')) and eta.get('dvd') < (now - 2419200))):
movie_ids.append(movie_id)
if coming_soon:
if len(movie_ids) >= limit:
break
# Don't list older movies
if ((not late and (not eta.get('dvd') and not eta.get('theater') or eta.get('dvd') and eta.get('dvd') > (now - 2419200))) or
(late and (eta.get('dvd', 0) > 0 or eta.get('theater')) and eta.get('dvd') < (now - 2419200))):
movie_ids.append(movie_id)
# Get all movie information
movies_raw = db.query(Movie) \
.options(joinedload_all('library.titles')) \
.options(joinedload_all('library.files')) \
.options(joinedload_all('files')) \
.filter(Movie.id.in_(movie_ids)) \
.all()
if len(movie_ids) >= limit:
break
# Create dict by movie id
movie_dict = {}
for movie in movies_raw:
movie_dict[movie.id] = movie
if len(movie_ids) > 0:
movies = []
for movie_id in movie_ids:
movies.append(movie_dict[movie_id].to_dict({
'library': {'titles': {}, 'files':{}},
'files': {},
}))
# Get all movie information
movies_raw = db.query(Movie) \
.options(joinedload_all('library.titles')) \
.options(joinedload_all('library.files')) \
.options(joinedload_all('files')) \
.filter(Movie.id.in_(movie_ids)) \
.all()
# Create dict by movie id
movie_dict = {}
for movie in movies_raw:
movie_dict[movie.id] = movie
for movie_id in movie_ids:
movies.append(movie_dict[movie_id].to_dict({
'library': {'titles': {}, 'files':{}},
'files': {},
}))
return {
'success': True,

Loading…
Cancel
Save