mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-26 15:52:42 +00:00
Fixed: Only fix cleanName when fix is needed
Avoid hitting DB for every artist on clean name housekeeper Co-Authored-By: taloth <taloth@users.noreply.github.com>
This commit is contained in:
parent
ace83498cd
commit
184ab745ae
3 changed files with 57 additions and 2 deletions
|
@ -0,0 +1,50 @@
|
|||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateCleanTitleForArtistFixture : CoreTest<UpdateCleanTitleForArtist>
|
||||
{
|
||||
[Test]
|
||||
public void should_update_clean_title()
|
||||
{
|
||||
var artist = Builder<Artist>.CreateNew()
|
||||
.With(s => s.Name = "Full Name")
|
||||
.With(s => s.CleanName = "unclean")
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IArtistRepository>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new[] { artist });
|
||||
|
||||
Subject.Clean();
|
||||
|
||||
Mocker.GetMock<IArtistRepository>()
|
||||
.Verify(v => v.Update(It.Is<Artist>(s => s.CleanName == "fullname")), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_unchanged_title()
|
||||
{
|
||||
var artist = Builder<Artist>.CreateNew()
|
||||
.With(s => s.Name = "Full Name")
|
||||
.With(s => s.CleanName = "fullname")
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IArtistRepository>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new[] { artist });
|
||||
|
||||
Subject.Clean();
|
||||
|
||||
Mocker.GetMock<IArtistRepository>()
|
||||
.Verify(v => v.Update(It.Is<Artist>(s => s.CleanName == "fullname")), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -200,6 +200,7 @@
|
|||
<Compile Include="Housekeeping\Housekeepers\FixFutureDownloadClientStatusTimesFixture.cs" />
|
||||
<Compile Include="Housekeeping\Housekeepers\FixFutureImportListStatusTimesFixture.cs" />
|
||||
<Compile Include="Housekeeping\Housekeepers\FixFutureIndexerStatusTimesFixture.cs" />
|
||||
<Compile Include="Housekeeping\Housekeepers\UpdateCleanTitleForArtistFixture.cs" />
|
||||
<Compile Include="Http\HttpProxySettingsProviderFixture.cs" />
|
||||
<Compile Include="Http\TorCacheHttpRequestInterceptorFixture.cs" />
|
||||
<Compile Include="ImportListTests\ImportListServiceFixture.cs" />
|
||||
|
|
|
@ -19,8 +19,12 @@ public void Clean()
|
|||
|
||||
artists.ForEach(s =>
|
||||
{
|
||||
s.CleanName = s.CleanName.CleanArtistName();
|
||||
_artistRepository.Update(s);
|
||||
var cleanName = s.Name.CleanArtistName();
|
||||
if (s.CleanName != cleanName)
|
||||
{
|
||||
s.CleanName = cleanName;
|
||||
_artistRepository.Update(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue