From dae5fce12c0efb65beb484fa4de84e8b81cfecd2 Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Wed, 18 Mar 2026 14:34:13 -0400 Subject: [PATCH] Updates to artist credit handling --- src/queries/cache.rs | 9 +++++++++ tests/integration.rs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/queries/cache.rs b/src/queries/cache.rs index 79eca8f..0bdb3c4 100644 --- a/src/queries/cache.rs +++ b/src/queries/cache.rs @@ -63,3 +63,12 @@ pub async fn purge_expired(db: &DatabaseConnection) -> DbResult { .await?; 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 { + let result = SearchCache::delete_many() + .filter(search_cache::Column::QueryKey.starts_with(prefix)) + .exec(db) + .await?; + Ok(result.rows_affected) +} diff --git a/tests/integration.rs b/tests/integration.rs index d370d40..6e96fb0 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -274,4 +274,22 @@ async fn test_search_cache_ttl() { // Purge expired let purged = queries::cache::purge_expired(conn).await.unwrap(); 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()); }