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 ClientSideCollectionAppState from 'App/State/ClientSideCollectionAppState';
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 PageContent from 'Components/Page/PageContent';
import PageContentBody from 'Components/Page/PageContentBody';
@ -49,6 +49,7 @@ import SeriesIndexSelectFooter from './Select/SeriesIndexSelectFooter';
import SeriesIndexSelectModeButton from './Select/SeriesIndexSelectModeButton';
import SeriesIndexSelectModeMenuItem from './Select/SeriesIndexSelectModeMenuItem';
import SeriesIndexFooter from './SeriesIndexFooter';
import SeriesIndexRefreshSeriesButton from './SeriesIndexRefreshSeriesButton';
import SeriesIndexTable from './Table/SeriesIndexTable';
import SeriesIndexTableOptions from './Table/SeriesIndexTableOptions';
import styles from './SeriesIndex.css';
@ -86,9 +87,6 @@ const SeriesIndex = withScrollPosition((props: SeriesIndexProps) => {
}: SeriesAppState & SeriesIndexAppState & ClientSideCollectionAppState =
useSelector(createSeriesClientSideCollectionItemsSelector('seriesIndex'));
const isRefreshingSeries = useSelector(
createCommandExecutingSelector(REFRESH_SERIES)
);
const isRssSyncExecuting = useSelector(
createCommandExecutingSelector(RSS_SYNC)
);
@ -106,14 +104,6 @@ const SeriesIndex = withScrollPosition((props: SeriesIndexProps) => {
dispatch(fetchQueueDetails({ all: true }));
}, [dispatch]);
const onRefreshSeriesPress = useCallback(() => {
dispatch(
executeCommand({
name: REFRESH_SERIES,
})
);
}, [dispatch]);
const onRssSyncPress = useCallback(() => {
dispatch(
executeCommand({
@ -227,13 +217,9 @@ const SeriesIndex = withScrollPosition((props: SeriesIndexProps) => {
<PageContent>
<PageToolbar>
<PageToolbarSection>
<PageToolbarButton
label="Update all"
iconName={icons.REFRESH}
spinningName={icons.REFRESH}
isSpinning={isRefreshingSeries}
isDisabled={hasNoSeries}
onPress={onRefreshSeriesPress}
<SeriesIndexRefreshSeriesButton
isSelectMode={isSelectMode}
selectedFilterKey={selectedFilterKey}
/>
<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);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _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>(), It.IsAny<bool>()));
@ -85,7 +85,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _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>(), It.IsAny<bool>()));
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(series);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _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>(), It.IsAny<bool>()));
@ -115,7 +115,7 @@ namespace NzbDrone.Core.Test.TvTests
GivenNewSeriesInfo(newSeriesInfo);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>()
.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);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>()
.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]
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>()
.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]
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>()
.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;
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>()
.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);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>()
.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);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>()
.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);
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Subject.Execute(new RefreshSeriesCommand(new List<int> { _series.Id }));
Mocker.GetMock<ISeriesService>()
.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))
.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>()
.Verify(v => v.Scan(_series), Times.Once());
@ -252,7 +252,7 @@ namespace NzbDrone.Core.Test.TvTests
.Setup(s => s.GetSeriesInfo(_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>()
.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;
namespace NzbDrone.Core.Tv.Commands
{
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 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;
}
public override bool SendUpdatesToClient => true;
public override bool UpdateScheduledTask => !SeriesId.HasValue;
public override bool UpdateScheduledTask => SeriesIds.Empty();
public override bool IsLongRunning => true;
}

@ -232,26 +232,29 @@ namespace NzbDrone.Core.Tv
var isNew = message.IsNewSeries;
_eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(trigger == CommandTrigger.Manual));
if (message.SeriesId.HasValue)
if (message.SeriesIds.Any())
{
var series = _seriesService.GetSeries(message.SeriesId.Value);
try
{
series = RefreshSeriesInfo(message.SeriesId.Value);
UpdateTags(series);
RescanSeries(series, isNew, trigger);
}
catch (SeriesNotFoundException)
foreach (var seriesId in message.SeriesIds)
{
_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;
var series = _seriesService.GetSeries(seriesId);
try
{
series = RefreshSeriesInfo(seriesId);
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);
}
catch (Exception e)
{
_logger.Error(e, "Couldn't refresh info for {0}", series);
UpdateTags(series);
RescanSeries(series, isNew, trigger);
throw;
}
}
}
else

@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
@ -18,12 +19,12 @@ namespace NzbDrone.Core.Tv
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)
{
_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.Events;
using NzbDrone.Core.Tv.Commands;
@ -18,7 +19,7 @@ namespace NzbDrone.Core.Tv
{
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));
File.WriteAllText(path, "Fake Episode");
Commands.PostAndWait(new RefreshSeriesCommand(series.Id));
Commands.PostAndWait(new RefreshSeriesCommand(new List<int> { series.Id }));
Commands.WaitAll();

Loading…
Cancel
Save