New: refresh only selected or filtered series

Closes #5611
pull/5676/head
Stevie Robinson 1 year ago committed by GitHub
parent a117001de6
commit bf90c3cbdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,7 +9,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { SelectProvider } from 'App/SelectContext'; import { SelectProvider } from 'App/SelectContext';
import ClientSideCollectionAppState from 'App/State/ClientSideCollectionAppState'; import ClientSideCollectionAppState from 'App/State/ClientSideCollectionAppState';
import SeriesAppState, { SeriesIndexAppState } from 'App/State/SeriesAppState'; import SeriesAppState, { SeriesIndexAppState } from 'App/State/SeriesAppState';
import { REFRESH_SERIES, RSS_SYNC } from 'Commands/commandNames'; import { RSS_SYNC } from 'Commands/commandNames';
import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import LoadingIndicator from 'Components/Loading/LoadingIndicator';
import PageContent from 'Components/Page/PageContent'; import PageContent from 'Components/Page/PageContent';
import PageContentBody from 'Components/Page/PageContentBody'; import PageContentBody from 'Components/Page/PageContentBody';
@ -49,6 +49,7 @@ import SeriesIndexSelectFooter from './Select/SeriesIndexSelectFooter';
import SeriesIndexSelectModeButton from './Select/SeriesIndexSelectModeButton'; import SeriesIndexSelectModeButton from './Select/SeriesIndexSelectModeButton';
import SeriesIndexSelectModeMenuItem from './Select/SeriesIndexSelectModeMenuItem'; import SeriesIndexSelectModeMenuItem from './Select/SeriesIndexSelectModeMenuItem';
import SeriesIndexFooter from './SeriesIndexFooter'; import SeriesIndexFooter from './SeriesIndexFooter';
import SeriesIndexRefreshSeriesButton from './SeriesIndexRefreshSeriesButton';
import SeriesIndexTable from './Table/SeriesIndexTable'; import SeriesIndexTable from './Table/SeriesIndexTable';
import SeriesIndexTableOptions from './Table/SeriesIndexTableOptions'; import SeriesIndexTableOptions from './Table/SeriesIndexTableOptions';
import styles from './SeriesIndex.css'; import styles from './SeriesIndex.css';
@ -86,9 +87,6 @@ const SeriesIndex = withScrollPosition((props: SeriesIndexProps) => {
}: SeriesAppState & SeriesIndexAppState & ClientSideCollectionAppState = }: SeriesAppState & SeriesIndexAppState & ClientSideCollectionAppState =
useSelector(createSeriesClientSideCollectionItemsSelector('seriesIndex')); useSelector(createSeriesClientSideCollectionItemsSelector('seriesIndex'));
const isRefreshingSeries = useSelector(
createCommandExecutingSelector(REFRESH_SERIES)
);
const isRssSyncExecuting = useSelector( const isRssSyncExecuting = useSelector(
createCommandExecutingSelector(RSS_SYNC) createCommandExecutingSelector(RSS_SYNC)
); );
@ -106,14 +104,6 @@ const SeriesIndex = withScrollPosition((props: SeriesIndexProps) => {
dispatch(fetchQueueDetails({ all: true })); dispatch(fetchQueueDetails({ all: true }));
}, [dispatch]); }, [dispatch]);
const onRefreshSeriesPress = useCallback(() => {
dispatch(
executeCommand({
name: REFRESH_SERIES,
})
);
}, [dispatch]);
const onRssSyncPress = useCallback(() => { const onRssSyncPress = useCallback(() => {
dispatch( dispatch(
executeCommand({ executeCommand({
@ -227,13 +217,9 @@ const SeriesIndex = withScrollPosition((props: SeriesIndexProps) => {
<PageContent> <PageContent>
<PageToolbar> <PageToolbar>
<PageToolbarSection> <PageToolbarSection>
<PageToolbarButton <SeriesIndexRefreshSeriesButton
label="Update all" isSelectMode={isSelectMode}
iconName={icons.REFRESH} selectedFilterKey={selectedFilterKey}
spinningName={icons.REFRESH}
isSpinning={isRefreshingSeries}
isDisabled={hasNoSeries}
onPress={onRefreshSeriesPress}
/> />
<PageToolbarButton <PageToolbarButton

@ -0,0 +1,73 @@
import React, { useCallback, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useSelect } from 'App/SelectContext';
import ClientSideCollectionAppState from 'App/State/ClientSideCollectionAppState';
import SeriesAppState, { SeriesIndexAppState } from 'App/State/SeriesAppState';
import { REFRESH_SERIES } from 'Commands/commandNames';
import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton';
import { icons } from 'Helpers/Props';
import { executeCommand } from 'Store/Actions/commandActions';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
import createSeriesClientSideCollectionItemsSelector from 'Store/Selectors/createSeriesClientSideCollectionItemsSelector';
import getSelectedIds from 'Utilities/Table/getSelectedIds';
interface SeriesIndexRefreshSeriesButtonProps {
isSelectMode: boolean;
selectedFilterKey: string;
}
function SeriesIndexRefreshSeriesButton(
props: SeriesIndexRefreshSeriesButtonProps
) {
const isRefreshing = useSelector(
createCommandExecutingSelector(REFRESH_SERIES)
);
const {
items,
totalItems,
}: SeriesAppState & SeriesIndexAppState & ClientSideCollectionAppState =
useSelector(createSeriesClientSideCollectionItemsSelector('seriesIndex'));
const dispatch = useDispatch();
const { isSelectMode, selectedFilterKey } = props;
const [selectState] = useSelect();
const { selectedState } = selectState;
const selectedSeriesIds = useMemo(() => {
return getSelectedIds(selectedState);
}, [selectedState]);
const seriesToRefresh =
isSelectMode && selectedSeriesIds.length > 0
? selectedSeriesIds
: items.map((m) => m.id);
let refreshLabel = 'Update All';
if (selectedSeriesIds.length > 0) {
refreshLabel = 'Update Selected';
} else if (selectedFilterKey !== 'all') {
refreshLabel = 'Update Filtered';
}
const onPress = useCallback(() => {
dispatch(
executeCommand({
name: REFRESH_SERIES,
seriesIds: seriesToRefresh,
})
);
}, [dispatch, seriesToRefresh]);
return (
<PageToolbarButton
label={refreshLabel}
isSpinning={isRefreshing}
isDisabled={!totalItems}
iconName={icons.REFRESH}
onPress={onPress}
/>
);
}
export default SeriesIndexRefreshSeriesButton;

@ -68,7 +68,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo); GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() 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>(), 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>()));
@ -85,7 +85,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo); GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() 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>(), 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>()));
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(series); GivenNewSeriesInfo(series);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() 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>(), 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>()));
@ -115,7 +115,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo); GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvRageId == newSeriesInfo.TvRageId), It.IsAny<bool>(), It.IsAny<bool>())); .Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvRageId == newSeriesInfo.TvRageId), It.IsAny<bool>(), It.IsAny<bool>()));
@ -129,7 +129,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo); GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvMazeId == newSeriesInfo.TvMazeId), It.IsAny<bool>(), It.IsAny<bool>())); .Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvMazeId == newSeriesInfo.TvMazeId), It.IsAny<bool>(), It.IsAny<bool>()));
@ -138,7 +138,7 @@ namespace NzbDrone.Core.Test.TvTests
[Test] [Test]
public void should_log_error_if_tvdb_id_not_found() public void should_log_error_if_tvdb_id_not_found()
{ {
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Status == SeriesStatusType.Deleted), It.IsAny<bool>(), 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());
@ -149,7 +149,7 @@ namespace NzbDrone.Core.Test.TvTests
[Test] [Test]
public void should_mark_as_deleted_if_tvdb_id_not_found() public void should_mark_as_deleted_if_tvdb_id_not_found()
{ {
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Status == SeriesStatusType.Deleted), It.IsAny<bool>(), 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());
@ -162,7 +162,7 @@ namespace NzbDrone.Core.Test.TvTests
{ {
_series.Status = SeriesStatusType.Deleted; _series.Status = SeriesStatusType.Deleted;
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never()); .Verify(v => v.UpdateSeries(It.IsAny<Series>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never());
@ -178,7 +178,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo); GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvdbId == newSeriesInfo.TvdbId), It.IsAny<bool>(), It.IsAny<bool>())); .Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvdbId == newSeriesInfo.TvdbId), It.IsAny<bool>(), It.IsAny<bool>()));
@ -204,7 +204,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo); GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>(), It.IsAny<bool>())); .Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>(), It.IsAny<bool>()));
@ -224,7 +224,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo); GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>() Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>(), It.IsAny<bool>())); .Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>(), It.IsAny<bool>()));
@ -237,7 +237,7 @@ namespace NzbDrone.Core.Test.TvTests
.Setup(s => s.GetSeriesInfo(_series.Id)) .Setup(s => s.GetSeriesInfo(_series.Id))
.Throws(new IOException()); .Throws(new IOException());
Assert.Throws<IOException>(() => Subject.Execute(new RefreshSeriesCommand(_series.Id))); Assert.Throws<IOException>(() => Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id })));
Mocker.GetMock<IDiskScanService>() Mocker.GetMock<IDiskScanService>()
.Verify(v => v.Scan(_series), Times.Once()); .Verify(v => v.Scan(_series), Times.Once());
@ -252,7 +252,7 @@ namespace NzbDrone.Core.Test.TvTests
.Setup(s => s.GetSeriesInfo(_series.Id)) .Setup(s => s.GetSeriesInfo(_series.Id))
.Throws(new SeriesNotFoundException(_series.Id)); .Throws(new SeriesNotFoundException(_series.Id));
Subject.Execute(new RefreshSeriesCommand(_series.Id)); Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<IDiskScanService>() Mocker.GetMock<IDiskScanService>()
.Verify(v => v.Scan(_series), Times.Never()); .Verify(v => v.Scan(_series), Times.Never());

@ -1,25 +1,42 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.Tv.Commands namespace NzbDrone.Core.Tv.Commands
{ {
public class RefreshSeriesCommand : Command public class RefreshSeriesCommand : Command
{ {
public int? SeriesId { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public int SeriesId
{
get => 0;
set
{
if (SeriesIds.Empty())
{
SeriesIds.Add(value);
}
}
}
public List<int> SeriesIds { get; set; }
public bool IsNewSeries { get; set; } public bool IsNewSeries { get; set; }
public RefreshSeriesCommand() public RefreshSeriesCommand()
{ {
SeriesIds = new List<int>();
} }
public RefreshSeriesCommand(int? seriesId, bool isNewSeries = false) public RefreshSeriesCommand(List<int> seriesIds, bool isNewSeries = false)
{ {
SeriesId = seriesId; SeriesIds = seriesIds;
IsNewSeries = isNewSeries; IsNewSeries = isNewSeries;
} }
public override bool SendUpdatesToClient => true; public override bool SendUpdatesToClient => true;
public override bool UpdateScheduledTask => !SeriesId.HasValue; public override bool UpdateScheduledTask => SeriesIds.Empty();
public override bool IsLongRunning => true; public override bool IsLongRunning => true;
} }

@ -232,26 +232,29 @@ namespace NzbDrone.Core.Tv
var isNew = message.IsNewSeries; var isNew = message.IsNewSeries;
_eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(trigger == CommandTrigger.Manual)); _eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(trigger == CommandTrigger.Manual));
if (message.SeriesId.HasValue) if (message.SeriesIds.Any())
{ {
var series = _seriesService.GetSeries(message.SeriesId.Value); foreach (var seriesId in message.SeriesIds)
try
{
series = RefreshSeriesInfo(message.SeriesId.Value);
UpdateTags(series);
RescanSeries(series, isNew, trigger);
}
catch (SeriesNotFoundException)
{ {
_logger.Error("Series '{0}' (tvdbid {1}) was not found, it may have been removed from TheTVDB.", series.Title, series.TvdbId); var series = _seriesService.GetSeries(seriesId);
}
catch (Exception e) try
{ {
_logger.Error(e, "Couldn't refresh info for {0}", series); series = RefreshSeriesInfo(seriesId);
UpdateTags(series); UpdateTags(series);
RescanSeries(series, isNew, trigger); RescanSeries(series, isNew, trigger);
throw; }
catch (SeriesNotFoundException)
{
_logger.Error("Series '{0}' (tvdbid {1}) was not found, it may have been removed from TheTVDB.", series.Title, series.TvdbId);
}
catch (Exception e)
{
_logger.Error(e, "Couldn't refresh info for {0}", series);
UpdateTags(series);
RescanSeries(series, isNew, trigger);
throw;
}
} }
} }
else else

@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -18,12 +19,12 @@ namespace NzbDrone.Core.Tv
public void Handle(SeriesAddedEvent message) public void Handle(SeriesAddedEvent message)
{ {
_commandQueueManager.Push(new RefreshSeriesCommand(message.Series.Id, true)); _commandQueueManager.Push(new RefreshSeriesCommand(new List<int> { message.Series.Id }, true));
} }
public void Handle(SeriesImportedEvent message) public void Handle(SeriesImportedEvent message)
{ {
_commandQueueManager.PushMany(message.SeriesIds.Select(s => new RefreshSeriesCommand(s, true)).ToList()); _commandQueueManager.PushMany(message.SeriesIds.Select(s => new RefreshSeriesCommand(new List<int> { s }, true)).ToList());
} }
} }
} }

@ -1,3 +1,4 @@
using System.Collections.Generic;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tv.Commands; using NzbDrone.Core.Tv.Commands;
@ -18,7 +19,7 @@ namespace NzbDrone.Core.Tv
{ {
if (message.Series.SeriesType != message.OldSeries.SeriesType) if (message.Series.SeriesType != message.OldSeries.SeriesType)
{ {
_commandQueueManager.Push(new RefreshSeriesCommand(message.Series.Id, false)); _commandQueueManager.Push(new RefreshSeriesCommand(new List<int> { message.Series.Id }, false));
} }
} }
} }

@ -305,7 +305,7 @@ namespace NzbDrone.Integration.Test
Directory.CreateDirectory(Path.GetDirectoryName(path)); Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllText(path, "Fake Episode"); File.WriteAllText(path, "Fake Episode");
Commands.PostAndWait(new RefreshSeriesCommand(series.Id)); Commands.PostAndWait(new RefreshSeriesCommand(new List<int> { series.Id }));
Commands.WaitAll(); Commands.WaitAll();

Loading…
Cancel
Save