Move status_get outside index
This commit is contained in:
@@ -38,14 +38,6 @@ class MediaIndex(MultiTreeBasedIndex):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_with_status(self, db, status = [], with_doc = True):
|
|
||||||
|
|
||||||
status = list(status if isinstance(status, (list, tuple)) else [status])
|
|
||||||
|
|
||||||
for s in status:
|
|
||||||
for ms in db.get_many('media_status', s, with_doc = with_doc):
|
|
||||||
yield ms['doc'] if with_doc else ms
|
|
||||||
|
|
||||||
|
|
||||||
class MediaStatusIndex(TreeBasedIndex):
|
class MediaStatusIndex(TreeBasedIndex):
|
||||||
_version = 1
|
_version = 1
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class MediaPlugin(MediaBase):
|
|||||||
addEvent('app.load', self.addSingleDeleteView, priority = 100)
|
addEvent('app.load', self.addSingleDeleteView, priority = 100)
|
||||||
|
|
||||||
addEvent('media.get', self.get)
|
addEvent('media.get', self.get)
|
||||||
|
addEvent('media.with_status', self.withStatus)
|
||||||
addEvent('media.list', self.list)
|
addEvent('media.list', self.list)
|
||||||
addEvent('media.delete', self.delete)
|
addEvent('media.delete', self.delete)
|
||||||
addEvent('media.restatus', self.restatus)
|
addEvent('media.restatus', self.restatus)
|
||||||
@@ -146,6 +147,16 @@ class MediaPlugin(MediaBase):
|
|||||||
'media': media,
|
'media': media,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def withStatus(self, status, with_doc = True):
|
||||||
|
|
||||||
|
db = get_db()
|
||||||
|
|
||||||
|
status = list(status if isinstance(status, (list, tuple)) else [status])
|
||||||
|
|
||||||
|
for s in status:
|
||||||
|
for ms in db.get_many('media_status', s, with_doc = with_doc):
|
||||||
|
yield ms['doc'] if with_doc else ms
|
||||||
|
|
||||||
def list(self, types = None, status = None, release_status = None, status_or = False, limit_offset = None, starts_with = None, search = None):
|
def list(self, types = None, status = None, release_status = None, status_or = False, limit_offset = None, starts_with = None, search = None):
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
@@ -172,13 +183,13 @@ class MediaPlugin(MediaBase):
|
|||||||
# Filter on movie status
|
# Filter on movie status
|
||||||
if status and len(status) > 0:
|
if status and len(status) > 0:
|
||||||
filter_by['media_status'] = set()
|
filter_by['media_status'] = set()
|
||||||
for media_status in db.run('media', 'with_status', status, with_doc = False):
|
for media_status in fireEvent('media.with_status', status, with_doc = False, single = True):
|
||||||
filter_by['media_status'].add(media_status.get('_id'))
|
filter_by['media_status'].add(media_status.get('_id'))
|
||||||
|
|
||||||
# Filter on release status
|
# Filter on release status
|
||||||
if release_status and len(release_status) > 0:
|
if release_status and len(release_status) > 0:
|
||||||
filter_by['release_status'] = set()
|
filter_by['release_status'] = set()
|
||||||
for release_status in db.run('release', 'with_status', release_status, with_doc = False):
|
for release_status in fireEvent('media.with_status', release_status, with_doc = False, single = True):
|
||||||
filter_by['release_status'].add(release_status.get('media_id'))
|
filter_by['release_status'].add(release_status.get('media_id'))
|
||||||
|
|
||||||
# Add search filters
|
# Add search filters
|
||||||
@@ -285,13 +296,13 @@ class MediaPlugin(MediaBase):
|
|||||||
# Filter on movie status
|
# Filter on movie status
|
||||||
if status and len(status) > 0:
|
if status and len(status) > 0:
|
||||||
filter_by['media_status'] = set()
|
filter_by['media_status'] = set()
|
||||||
for media_status in db.run('media', 'with_status', status, with_doc = False):
|
for media_status in fireEvent('media.with_status', status, with_doc = False, single = True):
|
||||||
filter_by['media_status'].add(media_status.get('_id'))
|
filter_by['media_status'].add(media_status.get('_id'))
|
||||||
|
|
||||||
# Filter on release status
|
# Filter on release status
|
||||||
if release_status and len(release_status) > 0:
|
if release_status and len(release_status) > 0:
|
||||||
filter_by['release_status'] = set()
|
filter_by['release_status'] = set()
|
||||||
for release_status in db.run('release', 'with_status', release_status, with_doc = False):
|
for release_status in fireEvent('media.with_status', release_status, with_doc = False, single = True):
|
||||||
filter_by['release_status'].add(release_status.get('media_id'))
|
filter_by['release_status'].add(release_status.get('media_id'))
|
||||||
|
|
||||||
# Filter by combining ids
|
# Filter by combining ids
|
||||||
|
|||||||
@@ -74,9 +74,7 @@ class MovieSearcher(SearcherBase, MovieTypeBase):
|
|||||||
self.in_progress = True
|
self.in_progress = True
|
||||||
fireEvent('notify.frontend', type = 'movie.searcher.started', data = True, message = 'Full search started')
|
fireEvent('notify.frontend', type = 'movie.searcher.started', data = True, message = 'Full search started')
|
||||||
|
|
||||||
db = get_db()
|
medias = [x['_id'] for x in fireEvent('media.with_status', 'active', with_doc = False, single = True)]
|
||||||
|
|
||||||
medias = [x['_id'] for x in db.run('media', 'with_status', 'active', with_doc = False)]
|
|
||||||
random.shuffle(medias)
|
random.shuffle(medias)
|
||||||
|
|
||||||
total = len(medias)
|
total = len(medias)
|
||||||
@@ -316,9 +314,9 @@ class MovieSearcher(SearcherBase, MovieTypeBase):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def tryNextReleaseView(self, id = None, **kwargs):
|
def tryNextReleaseView(self, media_id = None, **kwargs):
|
||||||
|
|
||||||
trynext = self.tryNextRelease(id, manual = True)
|
trynext = self.tryNextRelease(media_id, manual = True)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'success': trynext
|
'success': trynext
|
||||||
@@ -328,7 +326,7 @@ class MovieSearcher(SearcherBase, MovieTypeBase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
db = get_db()
|
db = get_db()
|
||||||
rels = db.run('media', 'with_status', media_id, status = ['snatched', 'done'])
|
rels = fireEvent('media.with_status', ['snatched', 'done'], single = True)
|
||||||
|
|
||||||
for rel in rels:
|
for rel in rels:
|
||||||
rel['status'] = 'ignored'
|
rel['status'] = 'ignored'
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ class Suggestion(Plugin):
|
|||||||
else:
|
else:
|
||||||
|
|
||||||
if not movies or len(movies) == 0:
|
if not movies or len(movies) == 0:
|
||||||
db = get_db()
|
active_movies = fireEvent('media.with_status', ['active', 'done'], single = True)
|
||||||
active_movies = db.run('media', 'with_status', ['active', 'done'])
|
|
||||||
movies = [getIdentifier(x) for x in active_movies]
|
movies = [getIdentifier(x) for x in active_movies]
|
||||||
|
|
||||||
if not ignored or len(ignored) == 0:
|
if not ignored or len(ignored) == 0:
|
||||||
@@ -86,7 +85,7 @@ class Suggestion(Plugin):
|
|||||||
# Get new results and add them
|
# Get new results and add them
|
||||||
if len(new_suggestions) - 1 < limit:
|
if len(new_suggestions) - 1 < limit:
|
||||||
db = get_db()
|
db = get_db()
|
||||||
active_movies = db.run('media', 'with_status', ['active', 'done'])
|
active_movies = fireEvent('media.with_status', ['active', 'done'], single = True)
|
||||||
movies = [getIdentifier(x) for x in active_movies]
|
movies = [getIdentifier(x) for x in active_movies]
|
||||||
movies.extend(seen)
|
movies.extend(seen)
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Dashboard(Plugin):
|
|||||||
limit = tryInt(splt[0])
|
limit = tryInt(splt[0])
|
||||||
|
|
||||||
# Get all active medias
|
# Get all active medias
|
||||||
active_ids = [x['_id'] for x in db.run('media', 'with_status', 'active', with_doc = False)]
|
active_ids = [x['_id'] for x in fireEvent('media.with_status', 'active', with_doc = False, single = True)]
|
||||||
|
|
||||||
medias = []
|
medias = []
|
||||||
now_year = date.today().year
|
now_year = date.today().year
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import traceback
|
|||||||
|
|
||||||
from couchpotato import get_db, tryInt
|
from couchpotato import get_db, tryInt
|
||||||
from couchpotato.api import addApiView
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.event import addEvent
|
from couchpotato.core.event import addEvent, fireEvent
|
||||||
from couchpotato.core.helpers.encoding import toUnicode
|
from couchpotato.core.helpers.encoding import toUnicode
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
@@ -41,7 +41,7 @@ class ProfilePlugin(Plugin):
|
|||||||
# Get all active movies without profile
|
# Get all active movies without profile
|
||||||
try:
|
try:
|
||||||
db = get_db()
|
db = get_db()
|
||||||
medias = db.run('media', 'with_status', ['active'])
|
medias = fireEvent('media.with_status', 'active', single = True)
|
||||||
|
|
||||||
profile_ids = [x.get('_id') for x in self.all()]
|
profile_ids = [x.get('_id') for x in self.all()]
|
||||||
default_id = profile_ids[0]
|
default_id = profile_ids[0]
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class Release(Plugin):
|
|||||||
db = get_db()
|
db = get_db()
|
||||||
|
|
||||||
# get movies last_edit more than a week ago
|
# get movies last_edit more than a week ago
|
||||||
medias = db.run('media', 'with_status', ['done'])
|
medias = fireEvent('media.with_status', 'done', single = True)
|
||||||
|
|
||||||
for media in medias:
|
for media in medias:
|
||||||
if media.get('last_edit', 0) > (now - week):
|
if media.get('last_edit', 0) > (now - week):
|
||||||
|
|||||||
Reference in New Issue
Block a user