playlist: Improve speed in PlaylistQuery class

Implement the col_clause method for faster, sqlite-based querying. This
will only make a difference if the "fast" kwarg is set to True.
This commit is contained in:
Jan Holthuis 2019-02-15 18:44:58 +01:00
parent a80a07f093
commit 19b92e1199

View file

@ -19,7 +19,7 @@ import beets
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['playlist']
@ -51,6 +51,14 @@ class PlaylistQuery(beets.dbcore.FieldQuery):
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