From 16a98805832f7c2f9963606542e24e88ee0c60a8 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sat, 1 Apr 2023 19:45:07 +0100 Subject: [PATCH] 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). --- app/models.py | 2 +- app/musicmuster.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index c0f1396..e69431a 100644 --- a/app/models.py +++ b/app/models.py @@ -731,7 +731,7 @@ class Tracks(Base): return ( session.execute( select(cls) - .where(cls.title.ilike(f"%{text}%")) + .where(cls.title.like(f"{text}%")) .order_by(cls.title) ) .scalars() diff --git a/app/musicmuster.py b/app/musicmuster.py index 0f3dad2..a4a3124 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1837,7 +1837,7 @@ class DbDialog(QDialog): """Handle text typed in search box""" self.ui.matchList.clear() - if len(s) > 1: + if len(s) > 0: if self.ui.radioTitle.isChecked(): matches = Tracks.search_titles(self.session, s) else: