Improve track search performance

Searching for a track was wrapping the search string in % signs
(wildcards). The leading % meant the database didn't use the index.
Dropped leading % (user can add it manually if needed).
This commit is contained in:
Keith Edmunds 2023-04-01 19:45:07 +01:00
parent 69bfd3cff9
commit 16a9880583
2 changed files with 2 additions and 2 deletions

View File

@ -731,7 +731,7 @@ class Tracks(Base):
return ( return (
session.execute( session.execute(
select(cls) select(cls)
.where(cls.title.ilike(f"%{text}%")) .where(cls.title.like(f"{text}%"))
.order_by(cls.title) .order_by(cls.title)
) )
.scalars() .scalars()

View File

@ -1837,7 +1837,7 @@ class DbDialog(QDialog):
"""Handle text typed in search box""" """Handle text typed in search box"""
self.ui.matchList.clear() self.ui.matchList.clear()
if len(s) > 1: if len(s) > 0:
if self.ui.radioTitle.isChecked(): if self.ui.radioTitle.isChecked():
matches = Tracks.search_titles(self.session, s) matches = Tracks.search_titles(self.session, s)
else: else: