Merge pull request 'Fix phantom duplicate tracks created on Merged file ingestion' (#3) from DEV into main
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -334,18 +334,31 @@ pub async fn approve_and_finalize(
|
|||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Check if track already exists (e.g. previously approved but pending not cleaned up)
|
// Check if track already exists by file_hash (re-approval of same file)
|
||||||
let existing: Option<(i64,)> = sqlx::query_as("SELECT id FROM tracks WHERE file_hash = $1")
|
let existing: Option<(i64,)> = sqlx::query_as("SELECT id FROM tracks WHERE file_hash = $1")
|
||||||
.bind(&pt.file_hash)
|
.bind(&pt.file_hash)
|
||||||
.fetch_optional(pool)
|
.fetch_optional(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some((track_id,)) = existing {
|
if let Some((track_id,)) = existing {
|
||||||
// Already finalized — just mark pending as approved
|
|
||||||
update_pending_status(pool, pending_id, "approved", None).await?;
|
update_pending_status(pool, pending_id, "approved", None).await?;
|
||||||
return Ok(track_id);
|
return Ok(track_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if track already exists by storage_path (Merged: different quality file landed
|
||||||
|
// at the same destination, source was deleted — don't create a phantom duplicate)
|
||||||
|
let existing_path: Option<(i64,)> = sqlx::query_as(
|
||||||
|
"SELECT id FROM tracks WHERE storage_path = $1 AND NOT hidden"
|
||||||
|
)
|
||||||
|
.bind(storage_path)
|
||||||
|
.fetch_optional(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Some((track_id,)) = existing_path {
|
||||||
|
update_pending_status(pool, pending_id, "merged", None).await?;
|
||||||
|
return Ok(track_id);
|
||||||
|
}
|
||||||
|
|
||||||
let artist_name = pt.norm_artist.as_deref().unwrap_or("Unknown Artist");
|
let artist_name = pt.norm_artist.as_deref().unwrap_or("Unknown Artist");
|
||||||
let artist_id = upsert_artist(pool, artist_name).await?;
|
let artist_id = upsert_artist(pool, artist_name).await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user