Skip to content

Commit

Permalink
New: Only sync indexers with matching app tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Qstick committed May 11, 2022
1 parent 1a71375 commit af50a1d
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/NzbDrone.Core/Applications/ApplicationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.ThingiProvider.Events;

namespace NzbDrone.Core.Applications
Expand Down Expand Up @@ -69,7 +70,10 @@ public void HandleAsync(ProviderAddedEvent<IIndexer> message)

foreach (var app in enabledApps)
{
ExecuteAction(a => a.AddIndexer((IndexerDefinition)message.Definition), app);
if (ShouldHandleIndexer(app.Definition, message.Definition))
{
ExecuteAction(a => a.AddIndexer((IndexerDefinition)message.Definition), app);
}
}
}

Expand Down Expand Up @@ -157,14 +161,14 @@ private void SyncIndexers(List<IApplication> applications, List<IndexerDefinitio

if (indexerMappings.Any(x => x.IndexerId == definition.Id))
{
if (((ApplicationDefinition)app.Definition).SyncLevel == ApplicationSyncLevel.FullSync)
if (((ApplicationDefinition)app.Definition).SyncLevel == ApplicationSyncLevel.FullSync && ShouldHandleIndexer(app.Definition, indexer))
{
ExecuteAction(a => a.UpdateIndexer(definition), app);
}
}
else
{
if (indexer.Enable)
if (indexer.Enable && ShouldHandleIndexer(app.Definition, indexer))
{
ExecuteAction(a => a.AddIndexer(definition), app);
}
Expand All @@ -187,6 +191,24 @@ private void SyncIndexers(List<IApplication> applications, List<IndexerDefinitio
}
}

private bool ShouldHandleIndexer(ProviderDefinition app, ProviderDefinition indexer)
{
if (app.Tags.Empty())
{
_logger.Debug("No tags set for this application.");
return true;
}

if (app.Tags.Intersect(indexer.Tags).Any())
{
_logger.Debug("Application and indexer have one or more intersecting tags.");
return true;
}

_logger.Debug("{0} does not have any intersecting tags with {1}. Indexer will not be synced", app.Name, indexer.Name);
return false;
}

private void ExecuteAction(Action<IApplication> applicationAction, IApplication application)
{
try
Expand Down

0 comments on commit af50a1d

Please sign in to comment.