Merge pull request #40 from coissac/claude/fix-flac-cache-covers-011CUx5cZGpFGRhUnv6iuirw

Make is_valid_pk() async to use tokio::time::sleep
This commit is contained in:
coissac
2025-11-11 14:46:21 +01:00
committed by GitHub
3 changed files with 8 additions and 8 deletions

View File

@@ -144,7 +144,7 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
///
/// Ceci permet le progressive caching: les fichiers en cours de download sont acceptés
/// dès que le prebuffer est atteint, sans attendre le marker de completion.
fn is_valid_pk(&self, pk: &str) -> bool {
async fn is_valid_pk(&self, pk: &str) -> bool {
if self.get_database().get(pk, false).is_err() {
tracing::debug!("is_valid_pk({}): DB entry not found", pk);
return false;
@@ -158,7 +158,7 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
let mut attempts = 0;
while !file_path.exists() && attempts < 100 {
std::thread::sleep(std::time::Duration::from_millis(10));
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
attempts += 1;
}

View File

@@ -51,7 +51,7 @@ impl ReadHandle {
// Vérifier validité dans le cache
let cache = crate::manager::audio_cache()?;
if cache.is_valid_pk(&cache_pk) {
if cache.is_valid_pk(&cache_pk).await {
// Valide, avancer le curseur et retourner
self.cursor.fetch_add(1, Ordering::SeqCst);
return Ok(Some(PlaylistTrack::new(cache_pk)));
@@ -92,7 +92,7 @@ impl ReadHandle {
Some(record) => {
// Vérifier validité
let cache = crate::manager::audio_cache()?;
if cache.is_valid_pk(&record.cache_pk) {
if cache.is_valid_pk(&record.cache_pk).await {
Ok(Some(PlaylistTrack::new(record.cache_pk.clone())))
} else {
Ok(None)
@@ -125,7 +125,7 @@ impl ReadHandle {
for i in pos..core.len() {
if let Some(record) = core.get(i) {
if cache.is_valid_pk(&record.cache_pk) {
if cache.is_valid_pk(&record.cache_pk).await {
count += 1;
}
}
@@ -200,7 +200,7 @@ impl ReadHandle {
};
// Vérifier validité
if !cache.is_valid_pk(&record.cache_pk) {
if !cache.is_valid_pk(&record.cache_pk).await {
continue;
}

View File

@@ -30,7 +30,7 @@ impl WriteHandle {
// Vérifier que le pk existe dans le cache
let cache = crate::manager::audio_cache()?;
if !cache.is_valid_pk(&cache_pk) {
if !cache.is_valid_pk(&cache_pk).await {
return Err(crate::Error::CacheEntryNotFound(cache_pk));
}
@@ -59,7 +59,7 @@ impl WriteHandle {
// Vérifier tous les pks d'abord
let cache = crate::manager::audio_cache()?;
for pk in &cache_pks {
if !cache.is_valid_pk(pk) {
if !cache.is_valid_pk(pk).await {
return Err(crate::Error::CacheEntryNotFound(pk.clone()));
}
}