From e688dfadf7ba7b435d46030f204a841058b8c1ca Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 5 Sep 2024 14:56:36 +0300 Subject: [PATCH] Fixed: Refresh tags after updating autotags --- src/NzbDrone.Core/AutoTagging/AutoTaggingService.cs | 11 +++++++++++ src/NzbDrone.Core/AutoTagging/AutoTagsUpdatedEvent.cs | 8 ++++++++ src/Radarr.Api.V3/Tags/TagController.cs | 11 ++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core/AutoTagging/AutoTagsUpdatedEvent.cs diff --git a/src/NzbDrone.Core/AutoTagging/AutoTaggingService.cs b/src/NzbDrone.Core/AutoTagging/AutoTaggingService.cs index c65134134..6768a38f8 100644 --- a/src/NzbDrone.Core/AutoTagging/AutoTaggingService.cs +++ b/src/NzbDrone.Core/AutoTagging/AutoTaggingService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Common.Cache; using NzbDrone.Common.Extensions; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Movies; using NzbDrone.Core.RootFolders; @@ -22,14 +23,18 @@ namespace NzbDrone.Core.AutoTagging { private readonly IAutoTaggingRepository _repository; private readonly RootFolderService _rootFolderService; + private readonly IEventAggregator _eventAggregator; private readonly ICached> _cache; public AutoTaggingService(IAutoTaggingRepository repository, RootFolderService rootFolderService, + IEventAggregator eventAggregator, ICacheManager cacheManager) { _repository = repository; _rootFolderService = rootFolderService; + _eventAggregator = eventAggregator; + _cache = cacheManager.GetCache>(typeof(AutoTag), "autoTags"); } @@ -51,13 +56,17 @@ namespace NzbDrone.Core.AutoTagging public void Update(AutoTag autoTag) { _repository.Update(autoTag); + _cache.Clear(); + _eventAggregator.PublishEvent(new AutoTagsUpdatedEvent()); } public AutoTag Insert(AutoTag autoTag) { var result = _repository.Insert(autoTag); + _cache.Clear(); + _eventAggregator.PublishEvent(new AutoTagsUpdatedEvent()); return result; } @@ -65,7 +74,9 @@ namespace NzbDrone.Core.AutoTagging public void Delete(int id) { _repository.Delete(id); + _cache.Clear(); + _eventAggregator.PublishEvent(new AutoTagsUpdatedEvent()); } public List AllForTag(int tagId) diff --git a/src/NzbDrone.Core/AutoTagging/AutoTagsUpdatedEvent.cs b/src/NzbDrone.Core/AutoTagging/AutoTagsUpdatedEvent.cs new file mode 100644 index 000000000..730e3423d --- /dev/null +++ b/src/NzbDrone.Core/AutoTagging/AutoTagsUpdatedEvent.cs @@ -0,0 +1,8 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.AutoTagging +{ + public class AutoTagsUpdatedEvent : IEvent + { + } +} diff --git a/src/Radarr.Api.V3/Tags/TagController.cs b/src/Radarr.Api.V3/Tags/TagController.cs index 7ef41cedf..1776b51c0 100644 --- a/src/Radarr.Api.V3/Tags/TagController.cs +++ b/src/Radarr.Api.V3/Tags/TagController.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; +using NzbDrone.Core.AutoTagging; using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tags; @@ -11,7 +12,9 @@ using Radarr.Http.REST.Attributes; namespace Radarr.Api.V3.Tags { [V3ApiController] - public class TagController : RestControllerWithSignalR, IHandle + public class TagController : RestControllerWithSignalR, + IHandle, + IHandle { private readonly ITagService _tagService; @@ -59,5 +62,11 @@ namespace Radarr.Api.V3.Tags { BroadcastResourceChange(ModelAction.Sync); } + + [NonAction] + public void Handle(AutoTagsUpdatedEvent message) + { + BroadcastResourceChange(ModelAction.Sync); + } } }