changes include: allow GET endpoints, redirect to codey.lol instead of returning status 422, clean junk from ai endpoint, add misc endpoint, add methods to lyric_search_new.sources.cache, other misc/cleanup

This commit is contained in:
2025-01-21 19:16:23 -05:00
parent e95ef3b088
commit 38dbddd297
7 changed files with 148 additions and 23 deletions

View File

@@ -50,7 +50,6 @@ class Cache:
for res in redis_results:
(key, row) = res
if key == matched_id:
logging.info("Matched row: %s", row)
return LyricsResult(
artist=row['artist'],
song=row['song'],
@@ -112,6 +111,53 @@ class Cache:
sqlite_insert_id = await self.sqlite_store(lyr_result)
if sqlite_insert_id:
await self.redis_cache.redis_store(sqlite_insert_id, lyr_result)
async def sqlite_rowcount(self, where: Optional[str] = None, params: Optional[tuple] = None) -> int:
"""
Get rowcount for cached_lyrics DB
Args:
where (Optional[str]): WHERE ext for query if needed
params (Optional[tuple]): Parameters to query, if where is specified
Returns:
int: Number of rows found
"""
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
db_conn.row_factory = sqlite3.Row
query = f"SELECT count(id) AS rowcount FROM lyrics {where}".strip()
async with await db_conn.execute(query, params) as db_cursor:
result = await db_cursor.fetchone()
return result['rowcount']
async def sqlite_distinct(self, column: str) -> int:
"""
Get count of distinct values for a column
Args:
column (str): The column to check
Returns:
int: Number of distinct values found
"""
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
db_conn.row_factory = sqlite3.Row
query = f"SELECT COUNT(DISTINCT {column}) as distinct_items FROM lyrics"
async with await db_conn.execute(query) as db_cursor:
result = await db_cursor.fetchone()
return result['distinct_items']
async def sqlite_lyrics_length(self) -> int:
"""
Get total length of text stored for lyrics
Args:
None
Returns:
int: Total length of stored lyrics
"""
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
db_conn.row_factory = sqlite3.Row
query = "SELECT SUM(LENGTH(lyrics)) as lyrics_len FROM lyrics"
async with await db_conn.execute(query) as db_cursor:
result = await db_cursor.fetchone()
return result['lyrics_len']
async def sqlite_store(self, lyr_result: LyricsResult) -> int:
@@ -188,7 +234,7 @@ class Cache:
"""Check Redis First"""
logging.info("Checking redis cache for %s...",
logging.debug("Checking redis cache for %s...",
f"{artist} - {song}")
redis_result = await self.redis_cache.search(artist=artist,
song=song)

View File

@@ -105,7 +105,7 @@ class RedisCache:
if not is_random_search:
logging.debug("Redis: Searching normally first")
(artist, song) = self.sanitize_input(artist, song)
logging.info("Seeking: %s - %s", artist, song)
logging.debug("Seeking: %s - %s", artist, song)
search_res = await self.redis_client.ft().search(Query(
f"@artist:{artist} @song:{song}"
))