Skip to content

Commit

Permalink
playlist: Improve speed in PlaylistQuery class
Browse files Browse the repository at this point in the history
Implement the col_clause method for faster, sqlite-based querying. This
will only make a difference if the "fast" kwarg is set to True.
  • Loading branch information
Holzhaus committed Feb 15, 2019
1 parent 5205860 commit 7eb9866
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion beetsplug/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class PlaylistQuery(beets.dbcore.FieldQuery):
"""Matches files listed by a playlist file.
"""
def __init__(self, field, pattern, fast=False):
def __init__(self, field, pattern, fast=True):
super(PlaylistQuery, self).__init__(field, pattern, fast)
config = beets.config['playlistquery']

Expand Down Expand Up @@ -51,6 +51,14 @@ def __init__(self, field, pattern, fast=False):
os.path.join(relative_to, line.rstrip())
))

def col_clause(self):
if not self.paths:
# Playlist is empty
return '0', ()
clause = 'BYTELOWER(path) IN ({0})'.format(
', '.join('BYTELOWER(?)' for path in self.paths))
return clause, (beets.library.BLOB_TYPE(p) for p in self.paths)

def match(self, item):
return item.path in self.paths

Expand Down

0 comments on commit 7eb9866

Please sign in to comment.