change method used to determine whether lyrics are already stored to match method used to retrieve lyrics from SQLite

This commit is contained in:
codey 2025-01-19 08:25:42 -05:00
parent be807ae2c0
commit c82c18cfb7

View File

@ -80,9 +80,16 @@ class Cache:
"""
logging.debug("Checking whether %s is already stored",
artistsong.replace("\n", " - "))
check_query = "SELECT id FROM lyrics WHERE artistsong LIKE ? LIMIT 1"
params = (f"%{artistsong}%",)
check_query: str = 'SELECT id, artist, song FROM lyrics WHERE editdist3((lower(artist) || " " || lower(song)), (? || " " || ?))\
<= 410 ORDER BY editdist3((lower(artist) || " " || lower(song)), ?) ASC LIMIT 1'
artistsong_split = artistsong.split("\n", maxsplit=1)
artist = artistsong_split[0].lower()
song = artistsong_split[1].lower()
params = (artist, song, artistsong.lower())
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
await db_conn.enable_load_extension(True)
for ext in self.sqlite_exts:
await db_conn.load_extension(ext)
async with await db_conn.executescript(self.cache_pre_query) as _db_cursor:
async with await db_conn.execute(check_query, params) as db_cursor:
result = await db_cursor.fetchone()