feat: when scanning, skip known paths
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

In the future we'll have to check for updated time,
but this is a basic countermeasure to having to clear the db
and rescan the whole collection.
This commit is contained in:
Lys 2023-11-27 03:03:13 +02:00
parent c2d1110e4a
commit b6e7a36511
Signed by: lyssieth
GPG key ID: C9CF3D614FAA3940

View file

@ -2,7 +2,8 @@ use audiotags::MimeType;
use color_eyre::{Report, Result}; use color_eyre::{Report, Result};
use entities::{ use entities::{
cover_art, genre, music_folder, cover_art, genre, music_folder,
prelude::{CoverArt, Genre, MusicFolder}, prelude::{CoverArt, Genre, MusicFolder, Track},
track,
}; };
use futures::StreamExt; use futures::StreamExt;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -132,6 +133,17 @@ async fn handle_entry(
state: Arc<RwLock<ScanState>>, state: Arc<RwLock<ScanState>>,
) -> Result<()> { ) -> Result<()> {
let path = entry.path(); let path = entry.path();
{
let query = Track::find().filter(track::Column::Path.eq(path.to_string_lossy()));
let res = query.one(tx).await;
if let Ok(Some(_)) = res {
debug!("Skipping already scanned file {path:?}");
return Ok(());
}
}
let file_type = entry.file_type().await?; let file_type = entry.file_type().await?;
if !file_type.is_file() { if !file_type.is_file() {