From 88d516a6d4d9857059b750357cb18befd22d9d07 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 27 Sep 2021 22:58:04 -0500 Subject: [PATCH] Cleanup Unused Tags Housekeeper Fixes #6535 --- .../Housekeeping/Housekeepers/CleanupUnusedTags.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs index caab4d5d3..adc846eed 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs @@ -2,6 +2,7 @@ using System.Data; using System.Linq; using Dapper; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Housekeeping.Housekeepers @@ -22,9 +23,9 @@ public void Clean() var usedTags = new[] { "Movies", "Notifications", "DelayProfiles", "Restrictions", "ImportLists" } .SelectMany(v => GetUsedTags(v, mapper)) .Distinct() - .ToArray(); + .ToList(); - var usedTagsList = string.Join(",", usedTags.Select(d => d.ToString()).ToArray()); + var usedTagsList = usedTags.Select(d => d.ToString()).Join(","); mapper.Execute($"DELETE FROM Tags WHERE NOT Id IN ({usedTagsList})"); } @@ -32,7 +33,7 @@ public void Clean() private int[] GetUsedTags(string table, IDbConnection mapper) { - return mapper.Query>($"SELECT DISTINCT Tags FROM {table} WHERE NOT Tags = '[]'") + return mapper.Query>($"SELECT DISTINCT Tags FROM {table} WHERE NOT Tags = '[]' AND NOT Tags IS NULL") .SelectMany(x => x) .Distinct() .ToArray();