Trigger fewer signalr broadcasts

This commit is contained in:
ta264 2020-01-06 21:29:27 +00:00 committed by Mark McDowall
parent 9abdaca079
commit b05b7ec4ad
8 changed files with 41 additions and 31 deletions

View File

@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
.Verify(v => v.GetSceneTvdbMappings(10), Times.Never());
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Never());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never());
}
[Test]
@ -119,7 +119,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
Subject.Handle(new SeriesUpdatedEvent(_series));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.UseSceneNumbering == true), It.IsAny<bool>()), Times.Once());
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.UseSceneNumbering == true), It.IsAny<bool>(), It.IsAny<bool>()), Times.Once());
}
[Test]
@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
Subject.Handle(new SeriesUpdatedEvent(_series));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Once());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Once());
}
[Test]
@ -143,7 +143,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
Subject.Handle(new SeriesUpdatedEvent(_series));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Never());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never());
ExceptionVerification.ExpectedWarns(1);
}
@ -160,7 +160,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
Subject.Handle(new SeriesUpdatedEvent(_series));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Never());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never());
ExceptionVerification.ExpectedWarns(1);
}

View File

@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests
Subject.SetEpisodeMonitoredStatus(_series, null);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Once());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Once());
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.UpdateEpisodes(It.IsAny<List<Episode>>()), Times.Never());
@ -249,13 +249,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests
private void VerifySeasonMonitored(Func<Season, bool> predicate)
{
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => n.Monitored)), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => n.Monitored)), It.IsAny<bool>(), It.IsAny<bool>()));
}
private void VerifySeasonNotMonitored(Func<Season, bool> predicate)
{
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => !n.Monitored)), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => !n.Monitored)), It.IsAny<bool>(), It.IsAny<bool>()));
}
}
}

View File

@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests
Subject.SetEpisodeMonitoredStatus(_series, null);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Once());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Once());
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.UpdateEpisodes(It.IsAny<List<Episode>>()), Times.Never());
@ -273,13 +273,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests
private void VerifySeasonMonitored(Func<Season, bool> predicate)
{
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => n.Monitored)), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => n.Monitored)), It.IsAny<bool>(), It.IsAny<bool>()));
}
private void VerifySeasonNotMonitored(Func<Season, bool> predicate)
{
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => !n.Monitored)), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Where(predicate).All(n => !n.Monitored)), It.IsAny<bool>(), It.IsAny<bool>()));
}
}
}

View File

@ -83,7 +83,7 @@ namespace NzbDrone.Core.Test.TvTests
ExceptionVerification.ExpectedErrors(1);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Once());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Once());
}
[Test]

View File

@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 2).Monitored == true), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 2).Monitored == true), It.IsAny<bool>(), It.IsAny<bool>()));
}
[Test]
@ -84,7 +84,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 2).Monitored == false), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 2).Monitored == false), It.IsAny<bool>(), It.IsAny<bool>()));
}
[Test]
@ -100,7 +100,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 0).Monitored == false), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 0).Monitored == false), It.IsAny<bool>(), It.IsAny<bool>()));
}
[Test]
@ -114,7 +114,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvRageId == newSeriesInfo.TvRageId), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvRageId == newSeriesInfo.TvRageId), It.IsAny<bool>(), It.IsAny<bool>()));
}
[Test]
@ -128,7 +128,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvMazeId == newSeriesInfo.TvMazeId), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvMazeId == newSeriesInfo.TvMazeId), It.IsAny<bool>(), It.IsAny<bool>()));
}
[Test]
@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Status == SeriesStatusType.Deleted), It.IsAny<bool>()), Times.Once());
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Status == SeriesStatusType.Deleted), It.IsAny<bool>(), It.IsAny<bool>()), Times.Once());
ExceptionVerification.ExpectedErrors(1);
}
@ -148,7 +148,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Status == SeriesStatusType.Deleted), It.IsAny<bool>()), Times.Once());
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Status == SeriesStatusType.Deleted), It.IsAny<bool>(), It.IsAny<bool>()), Times.Once());
ExceptionVerification.ExpectedErrors(1);
}
@ -161,7 +161,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>()), Times.Never());
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never());
ExceptionVerification.ExpectedErrors(1);
}
@ -177,7 +177,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvdbId == newSeriesInfo.TvdbId), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvdbId == newSeriesInfo.TvdbId), It.IsAny<bool>(), It.IsAny<bool>()));
ExceptionVerification.ExpectedWarns(1);
}
@ -203,7 +203,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>(), It.IsAny<bool>()));
}
[Test]
@ -223,7 +223,7 @@ namespace NzbDrone.Core.Test.TvTests
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>()));
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>(), It.IsAny<bool>()));
}

View File

@ -102,8 +102,9 @@ namespace NzbDrone.Core.MediaCover
return Path.Combine(_coverRootFolder, seriesId.ToString());
}
private void EnsureCovers(Series series)
private bool EnsureCovers(Series series)
{
bool updated = false;
var toResize = new List<Tuple<MediaCover, bool>>();
foreach (var cover in series.Images)
@ -116,6 +117,7 @@ namespace NzbDrone.Core.MediaCover
if (!alreadyExists)
{
DownloadCover(series, cover);
updated = true;
}
}
catch (WebException e)
@ -143,6 +145,8 @@ namespace NzbDrone.Core.MediaCover
{
_semaphore.Release();
}
return updated;
}
private void DownloadCover(Series series, MediaCover cover)
@ -200,8 +204,11 @@ namespace NzbDrone.Core.MediaCover
public void HandleAsync(SeriesUpdatedEvent message)
{
EnsureCovers(message.Series);
_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Series));
var updated = EnsureCovers(message.Series);
if (updated)
{
_eventAggregator.PublishEvent(new MediaCoversUpdatedEvent(message.Series));
}
}
public void HandleAsync(SeriesDeletedEvent message)

View File

@ -65,7 +65,7 @@ namespace NzbDrone.Core.Tv
if (series.Status != SeriesStatusType.Deleted)
{
series.Status = SeriesStatusType.Deleted;
_seriesService.UpdateSeries(series);
_seriesService.UpdateSeries(series, publishUpdatedEvent: false);
_logger.Debug("Series marked as deleted on tvdb for {0}", series.Title);
_eventAggregator.PublishEvent(new SeriesUpdatedEvent(series));
}
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Tv
series.Seasons = UpdateSeasons(series, seriesInfo);
_seriesService.UpdateSeries(series);
_seriesService.UpdateSeries(series, publishUpdatedEvent: false);
_refreshEpisodeService.RefreshEpisodeInfo(series, episodes);
_logger.Debug("Finished series refresh for {0}", series.Title);

View File

@ -25,7 +25,7 @@ namespace NzbDrone.Core.Tv
void DeleteSeries(int seriesId, bool deleteFiles);
List<Series> GetAllSeries();
List<Series> AllForTag(int tagId);
Series UpdateSeries(Series series, bool updateEpisodesToMatchSeason = true);
Series UpdateSeries(Series series, bool updateEpisodesToMatchSeason = true, bool publishUpdatedEvent = true);
List<Series> UpdateSeries(List<Series> series, bool useExistingRelativeFolder);
bool SeriesPathExists(string folder);
void RemoveAddOptions(Series series);
@ -165,7 +165,7 @@ namespace NzbDrone.Core.Tv
// updateEpisodesToMatchSeason is an override for EpisodeMonitoredService to use so a change via Season pass doesn't get nuked by the seasons loop.
// TODO: Remove when seasons are split from series (or we come up with a better way to address this)
public Series UpdateSeries(Series series, bool updateEpisodesToMatchSeason = true)
public Series UpdateSeries(Series series, bool updateEpisodesToMatchSeason = true, bool publishUpdatedEvent = true)
{
var storedSeries = GetSeries(series.Id);
@ -186,7 +186,10 @@ namespace NzbDrone.Core.Tv
series.AddOptions = storedSeries.AddOptions;
var updatedSeries = _seriesRepository.Update(series);
_eventAggregator.PublishEvent(new SeriesEditedEvent(updatedSeries, storedSeries));
if (publishUpdatedEvent)
{
_eventAggregator.PublishEvent(new SeriesEditedEvent(updatedSeries, storedSeries));
}
return updatedSeries;
}