reparations

This commit is contained in:
codey 2025-01-18 14:46:05 -05:00
parent d7fef03f1b
commit bfe09e8afc
2 changed files with 19 additions and 15 deletions

View File

@ -50,7 +50,7 @@ class Cache:
artist=row['artist'],
song=row['song'],
lyrics=row['lyrics'],
src=f"{row['src']} (redis cache, id: {row['id']})",
src=f"{row['src']} (redis cache, id: {key})",
confidence=row['confidence']
)
else:
@ -171,18 +171,18 @@ class Cache:
else:
best_match = (result_tracks[0], 100)
if not best_match:
return None
if best_match:
(candidate, confidence) = best_match
matched = self.get_matched(redis_results=redis_result, matched_candidate=candidate,
confidence=confidence)
if matched:
time_end: float = time.time()
time_diff: float = time_end - time_start
matched.confidence = confidence
matched.time = time_diff
if matched:
logging.info("Found %s on redis cache, skipping SQLite...",
f"{artist} - {song}")
return matched

View File

@ -65,12 +65,16 @@ class RedisCache:
search_res = await self.redis_client.ft().search(
Query(f"@artist:{artist} @song:{song}"
))
search_res_out = [(result['id'], dict(json.loads(result['json'])))
search_res_out = [(result['id'].split(":",
maxsplit=1)[1][:-1], dict(json.loads(result['json'])))
for result in search_res.docs]
else:
random_redis_key = await self.redis_client.randomkey()
out_id = str(random_redis_key).split(":",
maxsplit=1)[1][:-1]
search_res = await self.redis_client.json().get(random_redis_key)
search_res_out = [(random_redis_key, search_res)]
search_res_out = [(out_id, search_res)]
return search_res_out
except: