fix: stored procedure and database cleanup fix (also fixes file copying)
All checks were successful
Update changelog / changelog (push) Successful in 26s

This commit is contained in:
2026-01-27 07:52:20 +01:00
parent 17b8bafccd
commit 6a92451776
3 changed files with 18 additions and 10 deletions

View File

@@ -13,7 +13,7 @@ public partial class _00000000000000_StoredProcedure : Migration
AS $$
BEGIN
DELETE FROM "Songs"
WHERE "State" = 0;
WHERE "State" = 1;
COMMIT;
END;

View File

@@ -44,9 +44,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Mapping\" />
<Folder Include="DTOs\" />
</ItemGroup>
</Project>

View File

@@ -349,7 +349,8 @@ public class Cli
{
File.Copy(
Path.Combine(currentPath, "Assets", "vinyl.png"),
Path.Combine(newMusicThumbnailPath, "default.png")
Path.Combine(newMusicThumbnailPath, "default.png"),
true
);
break;
}
@@ -357,7 +358,7 @@ public class Cli
currentPath = Path.Combine(currentPath, "..");
if (i == 5) Console.WriteLine("\n" +
"Error: Could not determine content root path. \n" +
"[Error] Could not determine content root path. \n" +
"Please place Assets/vinyl.png in your thumbnail path directory manually\n" +
"and rename it to default.png.");
}
@@ -385,7 +386,10 @@ public class Cli
int rowsAffected = 0;
// Retrieve orphaned songs
List<Song> orphanedSongs = db.Songs.Where(s => s.State == 1).ToList();
List<Song> orphanedSongs = db.Songs
.Where(s => s.State == 1)
.Include(s => s.Album)
.ToList();
// Ask if it's alright to remove them
// and related listening data permanently
@@ -413,11 +417,13 @@ public class Cli
// TODO: Remove song images if not used by any other resource
// ...
db.SaveChanges();
}
// Perform cleanup with stored procedure
rowsAffected += db.Database.ExecuteSqlRaw("CALL song_cleanup()");
// rowsAffected += songs.Count;
db.Database.ExecuteSqlRaw("CALL song_cleanup()");
rowsAffected += orphanedSongs.Count;
}
}
else Console.WriteLine("No orphaned songs found.");
@@ -434,13 +440,17 @@ public class Cli
{
db.Albums.RemoveRange(orphanedAlbums);
rowsAffected += orphanedAlbums.Count;
db.SaveChanges();
}
}
else Console.WriteLine("No orphaned albums found.");
// Retrieve orphaned artists (artists with no songs AND albums)
List<Artist> orphanedArtists = db.Artists.Where(a => a.Songs.Count == 0 && a.Albums.Count == 0).ToList();
Artist? unknownArtist = db.Artists.FirstOrDefault(a => a.NormalizedName == "[unknown artist]");
List<Artist> orphanedArtists = db.Artists
.Where(a => a.Songs.Count == 0 && a.Albums.Count == 0)
.ToList();
Artist? unknownArtist = db.Artists
.FirstOrDefault(a => a.NormalizedName == "[unknown artist]");
// Account for the [Unknown Artist],
// which is a meta-artist and shall