mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Fixed: Cleanup Tracks Orphaned in History
This commit is contained in:
parent
e2c1d57d8c
commit
f6fd675ad4
2 changed files with 68 additions and 0 deletions
|
@ -13,6 +13,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
{
|
{
|
||||||
private Artist _artist;
|
private Artist _artist;
|
||||||
private Album _album;
|
private Album _album;
|
||||||
|
private Track _track;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
|
@ -22,6 +23,9 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
|
|
||||||
_album = Builder<Album>.CreateNew()
|
_album = Builder<Album>.CreateNew()
|
||||||
.BuildNew();
|
.BuildNew();
|
||||||
|
|
||||||
|
_track = Builder<Track>.CreateNew()
|
||||||
|
.BuildNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenArtist()
|
private void GivenArtist()
|
||||||
|
@ -34,14 +38,21 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
Db.Insert(_album);
|
Db.Insert(_album);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenTrack()
|
||||||
|
{
|
||||||
|
Db.Insert(_track);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_delete_orphaned_items_by_artist()
|
public void should_delete_orphaned_items_by_artist()
|
||||||
{
|
{
|
||||||
GivenAlbum();
|
GivenAlbum();
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
var history = Builder<History.History>.CreateNew()
|
var history = Builder<History.History>.CreateNew()
|
||||||
.With(h => h.Quality = new QualityModel())
|
.With(h => h.Quality = new QualityModel())
|
||||||
.With(h => h.AlbumId = _album.Id)
|
.With(h => h.AlbumId = _album.Id)
|
||||||
|
.With(h => h.TrackId = _track.Id)
|
||||||
.BuildNew();
|
.BuildNew();
|
||||||
Db.Insert(history);
|
Db.Insert(history);
|
||||||
|
|
||||||
|
@ -53,10 +64,29 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
public void should_delete_orphaned_items_by_album()
|
public void should_delete_orphaned_items_by_album()
|
||||||
{
|
{
|
||||||
GivenArtist();
|
GivenArtist();
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
var history = Builder<History.History>.CreateNew()
|
var history = Builder<History.History>.CreateNew()
|
||||||
.With(h => h.Quality = new QualityModel())
|
.With(h => h.Quality = new QualityModel())
|
||||||
.With(h => h.ArtistId = _artist.Id)
|
.With(h => h.ArtistId = _artist.Id)
|
||||||
|
.With(h => h.TrackId = _track.Id)
|
||||||
|
.BuildNew();
|
||||||
|
Db.Insert(history);
|
||||||
|
|
||||||
|
Subject.Clean();
|
||||||
|
AllStoredModels.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_delete_orphaned_items_by_track()
|
||||||
|
{
|
||||||
|
GivenArtist();
|
||||||
|
GivenAlbum();
|
||||||
|
|
||||||
|
var history = Builder<History.History>.CreateNew()
|
||||||
|
.With(h => h.Quality = new QualityModel())
|
||||||
|
.With(h => h.ArtistId = _artist.Id)
|
||||||
|
.With(h => h.AlbumId = _album.Id)
|
||||||
.BuildNew();
|
.BuildNew();
|
||||||
Db.Insert(history);
|
Db.Insert(history);
|
||||||
|
|
||||||
|
@ -69,6 +99,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
{
|
{
|
||||||
GivenArtist();
|
GivenArtist();
|
||||||
GivenAlbum();
|
GivenAlbum();
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
var history = Builder<History.History>.CreateListOfSize(2)
|
var history = Builder<History.History>.CreateListOfSize(2)
|
||||||
.All()
|
.All()
|
||||||
|
@ -90,6 +121,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
{
|
{
|
||||||
GivenArtist();
|
GivenArtist();
|
||||||
GivenAlbum();
|
GivenAlbum();
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
var history = Builder<History.History>.CreateListOfSize(2)
|
var history = Builder<History.History>.CreateListOfSize(2)
|
||||||
.All()
|
.All()
|
||||||
|
@ -105,5 +137,28 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
AllStoredModels.Should().HaveCount(1);
|
AllStoredModels.Should().HaveCount(1);
|
||||||
AllStoredModels.Should().Contain(h => h.AlbumId == _album.Id);
|
AllStoredModels.Should().Contain(h => h.AlbumId == _album.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_delete_unorphaned_data_by_track()
|
||||||
|
{
|
||||||
|
GivenArtist();
|
||||||
|
GivenAlbum();
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
|
var history = Builder<History.History>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(h => h.Quality = new QualityModel())
|
||||||
|
.With(h => h.ArtistId = _artist.Id)
|
||||||
|
.With(h => h.AlbumId = _album.Id)
|
||||||
|
.TheFirst(1)
|
||||||
|
.With(h => h.TrackId = _track.Id)
|
||||||
|
.BuildListOfNew();
|
||||||
|
|
||||||
|
Db.InsertMany(history);
|
||||||
|
|
||||||
|
Subject.Clean();
|
||||||
|
AllStoredModels.Should().HaveCount(1);
|
||||||
|
AllStoredModels.Should().Contain(h => h.TrackId == _track.Id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
{
|
{
|
||||||
CleanupOrphanedByArtist();
|
CleanupOrphanedByArtist();
|
||||||
CleanupOrphanedByAlbum();
|
CleanupOrphanedByAlbum();
|
||||||
|
CleanupOrphanedByTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CleanupOrphanedByArtist()
|
private void CleanupOrphanedByArtist()
|
||||||
|
@ -40,5 +41,17 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
ON History.AlbumId = Albums.Id
|
ON History.AlbumId = Albums.Id
|
||||||
WHERE Albums.Id IS NULL)");
|
WHERE Albums.Id IS NULL)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CleanupOrphanedByTrack()
|
||||||
|
{
|
||||||
|
var mapper = _database.GetDataMapper();
|
||||||
|
|
||||||
|
mapper.ExecuteNonQuery(@"DELETE FROM History
|
||||||
|
WHERE Id IN (
|
||||||
|
SELECT History.Id FROM History
|
||||||
|
LEFT OUTER JOIN Tracks
|
||||||
|
ON History.TrackId = Tracks.Id
|
||||||
|
WHERE Tracks.Id IS NULL)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue