mirror of
https://github.com/Sonarr/Sonarr
synced 2025-02-25 07:23:16 +00:00
Debounce Command Notifications.
This commit is contained in:
parent
b7c5639a9d
commit
5b0e959d3f
1 changed files with 27 additions and 2 deletions
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using NzbDrone.Api.Extensions;
|
using NzbDrone.Api.Extensions;
|
||||||
using NzbDrone.Api.Validation;
|
using NzbDrone.Api.Validation;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
using NzbDrone.Common.TPL;
|
||||||
using NzbDrone.Core.Datastore.Events;
|
using NzbDrone.Core.Datastore.Events;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
@ -17,6 +18,8 @@ namespace NzbDrone.Api.Commands
|
||||||
{
|
{
|
||||||
private readonly IManageCommandQueue _commandQueueManager;
|
private readonly IManageCommandQueue _commandQueueManager;
|
||||||
private readonly IServiceFactory _serviceFactory;
|
private readonly IServiceFactory _serviceFactory;
|
||||||
|
private readonly Debouncer _debouncer;
|
||||||
|
private readonly Dictionary<int, CommandResource> _pendingUpdates;
|
||||||
|
|
||||||
public CommandModule(IManageCommandQueue commandQueueManager,
|
public CommandModule(IManageCommandQueue commandQueueManager,
|
||||||
IBroadcastSignalRMessage signalRBroadcaster,
|
IBroadcastSignalRMessage signalRBroadcaster,
|
||||||
|
@ -31,6 +34,10 @@ namespace NzbDrone.Api.Commands
|
||||||
GetResourceAll = GetStartedCommands;
|
GetResourceAll = GetStartedCommands;
|
||||||
|
|
||||||
PostValidator.RuleFor(c => c.Name).NotBlank();
|
PostValidator.RuleFor(c => c.Name).NotBlank();
|
||||||
|
|
||||||
|
_debouncer = new Debouncer(SendUpdates, TimeSpan.FromSeconds(0.1));
|
||||||
|
_pendingUpdates = new Dictionary<int, CommandResource>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandResource GetCommand(int id)
|
private CommandResource GetCommand(int id)
|
||||||
|
@ -59,8 +66,26 @@ namespace NzbDrone.Api.Commands
|
||||||
{
|
{
|
||||||
if (message.Command.Body.SendUpdatesToClient)
|
if (message.Command.Body.SendUpdatesToClient)
|
||||||
{
|
{
|
||||||
BroadcastResourceChange(ModelAction.Updated, message.Command.ToResource());
|
lock (_pendingUpdates)
|
||||||
|
{
|
||||||
|
_pendingUpdates[message.Command.Id] = message.Command.ToResource();
|
||||||
|
}
|
||||||
|
_debouncer.Execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendUpdates()
|
||||||
|
{
|
||||||
|
lock (_pendingUpdates)
|
||||||
|
{
|
||||||
|
var pendingUpdates = _pendingUpdates.Values.ToArray();
|
||||||
|
_pendingUpdates.Clear();
|
||||||
|
|
||||||
|
foreach (var pendingUpdate in pendingUpdates)
|
||||||
|
{
|
||||||
|
BroadcastResourceChange(ModelAction.Updated, pendingUpdate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue