Proper movie list selection and optimization
This commit is contained in:
@@ -101,15 +101,11 @@ class MoviePlugin(Plugin):
|
||||
if not isinstance(status, (list, tuple)):
|
||||
status = [status]
|
||||
|
||||
|
||||
q = db.query(Movie) \
|
||||
.join(Movie.library, Library.titles) \
|
||||
.options(joinedload_all('library.titles')) \
|
||||
.options(joinedload_all('library.files')) \
|
||||
.options(joinedload_all('status')) \
|
||||
.options(joinedload_all('files')) \
|
||||
.filter(LibraryTitle.default == True) \
|
||||
.filter(or_(*[Movie.status.has(identifier = s) for s in status]))
|
||||
.filter(or_(*[Movie.status.has(identifier = s) for s in status])) \
|
||||
.group_by(Movie.id)
|
||||
|
||||
filter_or = []
|
||||
if starts_with:
|
||||
@@ -130,17 +126,32 @@ class MoviePlugin(Plugin):
|
||||
|
||||
q = q.order_by(asc(LibraryTitle.simple_title))
|
||||
|
||||
q = q.subquery()
|
||||
q2 = db.query(Movie).join((q, q.c.id == Movie.id)) \
|
||||
.options(joinedload_all('releases')) \
|
||||
.options(joinedload_all('profile.types')) \
|
||||
.options(joinedload_all('library.titles')) \
|
||||
.options(joinedload_all('library.files')) \
|
||||
.options(joinedload_all('status')) \
|
||||
.options(joinedload_all('files')) \
|
||||
|
||||
|
||||
if limit_offset:
|
||||
splt = limit_offset.split(',')
|
||||
limit = splt[0]
|
||||
offset = 0 if len(splt) is 1 else splt[1]
|
||||
q = q.limit(limit).offset(offset)
|
||||
q2 = q2.limit(limit).offset(offset)
|
||||
|
||||
results = q.all()
|
||||
|
||||
results = q2.all()
|
||||
movies = []
|
||||
for movie in results:
|
||||
temp = movie.to_dict(self.default_dict)
|
||||
temp = movie.to_dict({
|
||||
'profile': {'types': {}},
|
||||
'releases': {'files':{}, 'info': {}},
|
||||
'library': {'titles': {}, 'files':{}},
|
||||
'files': {},
|
||||
})
|
||||
movies.append(temp)
|
||||
|
||||
return movies
|
||||
@@ -159,7 +170,8 @@ class MoviePlugin(Plugin):
|
||||
.join(Movie.library, Library.titles) \
|
||||
.options(joinedload_all('library.titles')) \
|
||||
.filter(LibraryTitle.default == True) \
|
||||
.filter(or_(*[Movie.status.has(identifier = s) for s in status]))
|
||||
.filter(or_(*[Movie.status.has(identifier = s) for s in status])) \
|
||||
.group_by(Movie.id)
|
||||
|
||||
results = q.all()
|
||||
|
||||
|
||||
@@ -69,17 +69,18 @@ var MovieList = new Class({
|
||||
self.scrollspy.stop();
|
||||
}
|
||||
|
||||
Object.each(movies, function(info){
|
||||
Object.each(movies, function(movie){
|
||||
|
||||
// Attach proper actions
|
||||
var a = self.options.actions
|
||||
var actions = a[info.status.identifier.capitalize()] || a.Wanted || {};
|
||||
var a = self.options.actions,
|
||||
status = Status.get(movie.status_id);
|
||||
var actions = a[status.identifier.capitalize()] || a.Wanted || {};
|
||||
|
||||
var m = new Movie(self, {
|
||||
'actions': actions,
|
||||
'view': self.current_view,
|
||||
'onSelect': self.calculateSelected.bind(self)
|
||||
}, info);
|
||||
}, movie);
|
||||
$(m).inject(self.movie_list);
|
||||
m.fireEvent('injected');
|
||||
|
||||
|
||||
@@ -74,12 +74,13 @@ var Movie = new Class({
|
||||
// Add done releases
|
||||
Array.each(self.data.releases, function(release){
|
||||
|
||||
var q = self.quality.getElement('.q_'+ release.quality.identifier);
|
||||
if(!q && release.status.identifier == 'snatched')
|
||||
var q = self.addQuality(release.quality_id)
|
||||
var q = self.quality.getElement('.q_id'+ release.quality_id),
|
||||
status = Status.get(release.status_id);
|
||||
|
||||
if(!q && status.identifier == 'snatched')
|
||||
var q = self.addQuality(release.quality_id)
|
||||
if (q)
|
||||
q.addClass(release.status.identifier);
|
||||
q.addClass(status.identifier);
|
||||
|
||||
});
|
||||
|
||||
@@ -100,7 +101,7 @@ var Movie = new Class({
|
||||
var q = Quality.getQuality(quality_id);
|
||||
return new Element('span', {
|
||||
'text': q.label,
|
||||
'class': 'q_'+q.identifier
|
||||
'class': 'q_'+q.identifier + 'q_id' + q.quality_id
|
||||
}).inject(self.quality);
|
||||
|
||||
},
|
||||
@@ -121,7 +122,7 @@ var Movie = new Class({
|
||||
|
||||
return 'Unknown movie'
|
||||
},
|
||||
|
||||
|
||||
getUnprefixedTitle: function(t){
|
||||
if(t.substr(0, 4).toLowerCase() == 'the ')
|
||||
t = t.substr(4) + ', The';
|
||||
@@ -275,11 +276,15 @@ var ReleaseAction = new Class({
|
||||
).inject(self.release_container)
|
||||
|
||||
Array.each(self.movie.data.releases, function(release){
|
||||
|
||||
var status = Status.get(release.status_id),
|
||||
quality = Quality.getProfile(release.quality_id)
|
||||
|
||||
new Element('div', {
|
||||
'class': 'item ' + release.status.identifier
|
||||
'class': 'item ' + status.identifier
|
||||
}).adopt(
|
||||
new Element('span.name', {'text': self.get(release, 'name'), 'title': self.get(release, 'name')}),
|
||||
new Element('span.quality', {'text': release.quality.label}),
|
||||
new Element('span.quality', {'text': quality.label}),
|
||||
new Element('span.size', {'text': (self.get(release, 'size') || 'unknown')}),
|
||||
new Element('span.age', {'text': self.get(release, 'age')}),
|
||||
new Element('span.score', {'text': self.get(release, 'score')}),
|
||||
|
||||
@@ -20,6 +20,7 @@ class StatusPlugin(Plugin):
|
||||
'wanted': 'Wanted',
|
||||
'snatched': 'Snatched',
|
||||
'deleted': 'Deleted',
|
||||
'ignored': 'Ignored',
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -5,7 +5,13 @@ var StatusBase = new Class({
|
||||
|
||||
self.statuses = statuses;
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
get: function(id){
|
||||
return this.statuses.filter(function(status){
|
||||
return status.id == id
|
||||
}).pick()
|
||||
},
|
||||
|
||||
});
|
||||
window.Status = new StatusBase();
|
||||
|
||||
Reference in New Issue
Block a user