Optimize available char listing
This commit is contained in:
1 parent
347125365f
commit
bc94e90994
2 files changed
+47
-28
No files matched your search
@@ -278,7 +278,8 @@ class MovieBase(MovieTypeBase):
|
|||||||
|
|
||||||
def availableChars(self, status = None, release_status = None):
|
def availableChars(self, status = None, release_status = None):
|
||||||
|
|
||||||
chars = ''
|
status = status or []
|
||||||
|
release_status = release_status or []
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
@@ -288,28 +289,44 @@ class MovieBase(MovieTypeBase):
|
|||||||
if release_status and not isinstance(release_status, (list, tuple)):
|
if release_status and not isinstance(release_status, (list, tuple)):
|
||||||
release_status = [release_status]
|
release_status = [release_status]
|
||||||
|
|
||||||
q = db.query(Movie) \
|
q = db.query(Movie)
|
||||||
.outerjoin(Movie.releases, Movie.library, Library.titles, Movie.status) \
|
|
||||||
.options(joinedload_all('library.titles'))
|
|
||||||
|
|
||||||
# Filter on movie status
|
# Filter on movie status
|
||||||
if status and len(status) > 0:
|
if status and len(status) > 0:
|
||||||
q = q.filter(or_(*[Movie.status.has(identifier = s) for s in status]))
|
statuses = fireEvent('status.get', status, single = len(release_status) > 1)
|
||||||
|
statuses = [s.get('id') for s in statuses]
|
||||||
|
|
||||||
|
q = q.filter(Movie.status_id.in_(statuses))
|
||||||
|
|
||||||
# Filter on release status
|
# Filter on release status
|
||||||
if release_status and len(release_status) > 0:
|
if release_status and len(release_status) > 0:
|
||||||
q = q.filter(or_(*[Release.status.has(identifier = s) for s in release_status]))
|
|
||||||
|
|
||||||
results = q.all()
|
statuses = fireEvent('status.get', release_status, single = len(release_status) > 1)
|
||||||
|
statuses = [s.get('id') for s in statuses]
|
||||||
|
|
||||||
for movie in results:
|
q = q.join(Movie.releases) \
|
||||||
char = movie.library.titles[0].simple_title[0]
|
.filter(Release.status_id.in_(statuses))
|
||||||
char = char if char in ascii_lowercase else '#'
|
|
||||||
if char not in chars:
|
q = q.join(Library, LibraryTitle) \
|
||||||
chars += str(char)
|
.with_entities(LibraryTitle.simple_title) \
|
||||||
|
.filter(LibraryTitle.default == True)
|
||||||
|
|
||||||
|
titles = q.all()
|
||||||
|
|
||||||
|
chars = set()
|
||||||
|
for title in titles:
|
||||||
|
try:
|
||||||
|
char = title[0][0]
|
||||||
|
char = char if char in ascii_lowercase else '#'
|
||||||
|
chars.add(str(char))
|
||||||
|
except:
|
||||||
|
log.error('Failed getting title for %s', title.libraries_id)
|
||||||
|
|
||||||
|
if len(chars) == 25:
|
||||||
|
break
|
||||||
|
|
||||||
db.expire_all()
|
db.expire_all()
|
||||||
return ''.join(sorted(chars, key = str.lower))
|
return ''.join(sorted(chars))
|
||||||
|
|
||||||
def listView(self, **kwargs):
|
def listView(self, **kwargs):
|
||||||
|
|
||||||
|
|||||||
@@ -273,8 +273,25 @@ var MovieList = new Class({
|
|||||||
})
|
})
|
||||||
).addClass('search');
|
).addClass('search');
|
||||||
|
|
||||||
|
var available_chars;
|
||||||
self.filter_menu.addEvent('open', function(){
|
self.filter_menu.addEvent('open', function(){
|
||||||
self.navigation_search_input.focus();
|
self.navigation_search_input.focus();
|
||||||
|
|
||||||
|
// Get available chars and highlight
|
||||||
|
if(!available_chars && (self.navigation.isDisplayed() || self.navigation.isVisible()))
|
||||||
|
Api.request('movie.available_chars', {
|
||||||
|
'data': Object.merge({
|
||||||
|
'status': self.options.status
|
||||||
|
}, self.filter),
|
||||||
|
'onSuccess': function(json){
|
||||||
|
available_chars = json.chars
|
||||||
|
|
||||||
|
json.chars.split('').each(function(c){
|
||||||
|
self.letters[c.capitalize()].addClass('available')
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
self.filter_menu.addLink(
|
self.filter_menu.addLink(
|
||||||
@@ -311,21 +328,6 @@ var MovieList = new Class({
|
|||||||
}).inject(self.navigation_alpha);
|
}).inject(self.navigation_alpha);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get available chars and highlight
|
|
||||||
if(self.navigation.isDisplayed() || self.navigation.isVisible())
|
|
||||||
Api.request('movie.available_chars', {
|
|
||||||
'data': Object.merge({
|
|
||||||
'status': self.options.status
|
|
||||||
}, self.filter),
|
|
||||||
'onSuccess': function(json){
|
|
||||||
|
|
||||||
json.chars.split('').each(function(c){
|
|
||||||
self.letters[c.capitalize()].addClass('available')
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add menu or hide
|
// Add menu or hide
|
||||||
if (self.options.menu.length > 0)
|
if (self.options.menu.length > 0)
|
||||||
self.options.menu.each(function(menu_item){
|
self.options.menu.each(function(menu_item){
|
||||||
|
|||||||
Reference in new issue
Block a user