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>
pull/6/head
Qstick 5 years ago
parent ace83498cd
commit 184ab745ae

@ -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 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
artists.ForEach(s =>
{
s.CleanName = s.CleanName.CleanArtistName();
var cleanName = s.Name.CleanArtistName();
if (s.CleanName != cleanName)
{
s.CleanName = cleanName;
_artistRepository.Update(s);
}
});
}
}

Loading…
Cancel
Save