openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #29086
[Merge] lp:~minkus/openlp/naturalsortfix into lp:openlp
Chris Hill has proposed merging lp:~minkus/openlp/naturalsortfix into lp:openlp.
Commit message:
Search performance tweaks when performing natural sort - author, songbook, topic, theme, CCLI number search
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~minkus/openlp/naturalsortfix/+merge/290843
Some minor fixes that I picked up after merge 2637 for natural sorting:
x Author, Topics, Theme search now sort twice (once in database, then naturally in code). Removed the first sort.
x Changed all sorting to use in-place sort() rather than copy-string sorted(), as apparently there's a speed bonus (http://stackoverflow.com/questions/22442378/what-is-the-difference-between-sortedlist-vs-list-sort-python)
Hope this helps, sorry not to get this in the first merge!
--
Your team OpenLP Core is requested to review the proposed merge of lp:~minkus/openlp/naturalsortfix into lp:openlp.
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py 2016-04-03 11:14:17 +0000
+++ openlp/plugins/songs/lib/mediaitem.py 2016-04-03 21:31:16 +0000
@@ -194,13 +194,13 @@
log.debug('Authors Search')
search_string = '%' + search_keywords + '%'
search_results = self.plugin.manager.get_all_objects(
- Author, Author.display_name.like(search_string), Author.display_name.asc())
+ Author, Author.display_name.like(search_string))
self.display_results_author(search_results)
elif search_type == SongSearch.Topics:
log.debug('Topics Search')
search_string = '%' + search_keywords + '%'
search_results = self.plugin.manager.get_all_objects(
- Topic, Topic.name.like(search_string), Topic.name.asc())
+ Topic, Topic.name.like(search_string))
self.display_results_topic(search_results)
elif search_type == SongSearch.Books:
log.debug('Songbook Search')
@@ -215,7 +215,7 @@
log.debug('Theme Search')
search_string = '%' + search_keywords + '%'
search_results = self.plugin.manager.get_all_objects(
- Song, Song.theme_name.like(search_string), Song.theme_name.asc())
+ Song, Song.theme_name.like(search_string))
self.display_results_themes(search_results)
elif search_type == SongSearch.Copyright:
log.debug('Copyright Search')
@@ -285,10 +285,10 @@
"""
log.debug('display results Author')
self.list_view.clear()
- search_results = sorted(search_results, key=lambda author: get_natural_key(author.display_name))
+ search_results.sort(key=lambda author: get_natural_key(author.display_name))
for author in search_results:
- songs = sorted(author.songs, key=lambda song: song.sort_key)
- for song in songs:
+ author.songs.sort(key=lambda song: song.sort_key)
+ for song in author.songs:
# Do not display temporary songs
if song.temporary:
continue
@@ -306,8 +306,8 @@
"""
log.debug('display results Book')
self.list_view.clear()
- search_results = sorted(search_results, key=lambda songbook_entry:
- (get_natural_key(songbook_entry.songbook.name), get_natural_key(songbook_entry.entry)))
+ search_results.sort(key=lambda songbook_entry:
+ (get_natural_key(songbook_entry.songbook.name), get_natural_key(songbook_entry.entry)))
for songbook_entry in search_results:
if songbook_entry.song.temporary:
continue
@@ -325,10 +325,10 @@
"""
log.debug('display results Topic')
self.list_view.clear()
- search_results = sorted(search_results, key=lambda topic: get_natural_key(topic.name))
+ search_results.sort(key=lambda topic: get_natural_key(topic.name))
for topic in search_results:
- songs = sorted(topic.songs, key=lambda song: song.sort_key)
- for song in songs:
+ topic.songs.sort(key=lambda song: song.sort_key)
+ for song in topic.songs:
# Do not display temporary songs
if song.temporary:
continue
@@ -346,8 +346,8 @@
"""
log.debug('display results Themes')
self.list_view.clear()
- search_results = sorted(search_results, key=lambda song: (get_natural_key(song.theme_name),
- song.sort_key))
+ search_results.sort(key=lambda song: (get_natural_key(song.theme_name),
+ song.sort_key))
for song in search_results:
# Do not display temporary songs
if song.temporary:
@@ -366,9 +366,9 @@
"""
log.debug('display results CCLI number')
self.list_view.clear()
- songs = sorted(search_results, key=lambda song: (get_natural_key(song.ccli_number),
- song.sort_key))
- for song in songs:
+ search_results.sort(key=lambda song: (get_natural_key(song.ccli_number),
+ song.sort_key))
+ for song in search_results:
# Do not display temporary songs
if song.temporary:
continue
References