Compare commits

...

1 Commits

Author SHA1 Message Date
Connor Johnstone
dae5fce12c Updates to artist credit handling 2026-03-18 14:34:13 -04:00
2 changed files with 27 additions and 0 deletions

View File

@@ -63,3 +63,12 @@ pub async fn purge_expired(db: &DatabaseConnection) -> DbResult<u64> {
.await?; .await?;
Ok(result.rows_affected) Ok(result.rows_affected)
} }
/// Delete all cache entries whose key starts with the given prefix.
pub async fn purge_prefix(db: &DatabaseConnection, prefix: &str) -> DbResult<u64> {
let result = SearchCache::delete_many()
.filter(search_cache::Column::QueryKey.starts_with(prefix))
.exec(db)
.await?;
Ok(result.rows_affected)
}

View File

@@ -274,4 +274,22 @@ async fn test_search_cache_ttl() {
// Purge expired // Purge expired
let purged = queries::cache::purge_expired(conn).await.unwrap(); let purged = queries::cache::purge_expired(conn).await.unwrap();
assert_eq!(purged, 1); assert_eq!(purged, 1);
// Purge by prefix
queries::cache::set(conn, "artist_totals:1", "computed", "[10,5,3]", 3600)
.await
.unwrap();
queries::cache::set(conn, "artist_totals:2", "computed", "[20,10,5]", 3600)
.await
.unwrap();
queries::cache::set(conn, "other_key", "computed", "{}", 3600)
.await
.unwrap();
let purged = queries::cache::purge_prefix(conn, "artist_totals:").await.unwrap();
assert_eq!(purged, 2);
// other_key should still exist
let result = queries::cache::get(conn, "other_key").await.unwrap();
assert!(result.is_some());
} }