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