Optimize suggestion listing
This commit is contained in:
1 parent
88d512eacc
commit
a6ce114284
1 file changed
+14
-14
@@ -1,13 +1,13 @@
|
|||||||
from couchpotato import get_session
|
from couchpotato import get_session
|
||||||
from couchpotato.api import addApiView
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.event import fireEvent
|
from couchpotato.core.event import fireEvent
|
||||||
from couchpotato.core.helpers.encoding import ss
|
from couchpotato.core.helpers.variable import splitString
|
||||||
from couchpotato.core.helpers.variable import splitString, md5
|
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
from couchpotato.core.settings.model import Movie
|
from couchpotato.core.settings.model import Movie
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
from sqlalchemy.sql.expression import or_
|
from sqlalchemy.sql.expression import or_
|
||||||
|
|
||||||
|
|
||||||
class Suggestion(Plugin):
|
class Suggestion(Plugin):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -15,32 +15,32 @@ class Suggestion(Plugin):
|
|||||||
addApiView('suggestion.view', self.suggestView)
|
addApiView('suggestion.view', self.suggestView)
|
||||||
addApiView('suggestion.ignore', self.ignoreView)
|
addApiView('suggestion.ignore', self.ignoreView)
|
||||||
|
|
||||||
def suggestView(self, **kwargs):
|
def suggestView(self, limit = 6, **kwargs):
|
||||||
|
|
||||||
movies = splitString(kwargs.get('movies', ''))
|
movies = splitString(kwargs.get('movies', ''))
|
||||||
ignored = splitString(kwargs.get('ignored', ''))
|
ignored = splitString(kwargs.get('ignored', ''))
|
||||||
limit = kwargs.get('limit', 6)
|
|
||||||
|
|
||||||
if not movies or len(movies) == 0:
|
|
||||||
db = get_session()
|
|
||||||
active_movies = db.query(Movie) \
|
|
||||||
.filter(or_(*[Movie.status.has(identifier = s) for s in ['active', 'done']])).all()
|
|
||||||
movies = [x.library.identifier for x in active_movies]
|
|
||||||
|
|
||||||
if not ignored or len(ignored) == 0:
|
|
||||||
ignored = splitString(Env.prop('suggest_ignore', default = ''))
|
|
||||||
|
|
||||||
cached_suggestion = self.getCache('suggestion_cached')
|
cached_suggestion = self.getCache('suggestion_cached')
|
||||||
if cached_suggestion:
|
if cached_suggestion:
|
||||||
suggestions = cached_suggestion
|
suggestions = cached_suggestion
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
if not movies or len(movies) == 0:
|
||||||
|
db = get_session()
|
||||||
|
active_movies = db.query(Movie) \
|
||||||
|
.filter(or_(*[Movie.status.has(identifier = s) for s in ['active', 'done']])).all()
|
||||||
|
movies = [x.library.identifier for x in active_movies]
|
||||||
|
|
||||||
|
if not ignored or len(ignored) == 0:
|
||||||
|
ignored = splitString(Env.prop('suggest_ignore', default = ''))
|
||||||
|
|
||||||
suggestions = fireEvent('movie.suggest', movies = movies, ignore = ignored, single = True)
|
suggestions = fireEvent('movie.suggest', movies = movies, ignore = ignored, single = True)
|
||||||
self.setCache('suggestion_cached', suggestions, timeout = 6048000) # Cache for 10 weeks
|
self.setCache('suggestion_cached', suggestions, timeout = 6048000) # Cache for 10 weeks
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'success': True,
|
'success': True,
|
||||||
'count': len(suggestions),
|
'count': len(suggestions),
|
||||||
'suggestions': suggestions[:limit]
|
'suggestions': suggestions[:int(limit)]
|
||||||
}
|
}
|
||||||
|
|
||||||
def ignoreView(self, imdb = None, limit = 6, remove_only = False, **kwargs):
|
def ignoreView(self, imdb = None, limit = 6, remove_only = False, **kwargs):
|
||||||
|
|||||||
Reference in new issue
Block a user