diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs index 6ea8a1c5d..1c6a1a0c0 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Marr.Data; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Serializer; using NzbDrone.Core.Datastore; @@ -19,19 +20,19 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers { var mapper = _database.GetDataMapper(); - var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "ReleaseProfiles" } + var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers" } .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.ExecuteNonQuery($"DELETE FROM Tags WHERE NOT Id IN ({usedTagsList})"); } private int[] GetUsedTags(string table, IDataMapper mapper) { - return mapper.ExecuteReader($"SELECT DISTINCT Tags FROM {table} WHERE NOT Tags = '[]'", reader => reader.GetString(0)) + return mapper.ExecuteReader($"SELECT DISTINCT Tags FROM {table} WHERE NOT Tags = '[]' AND NOT Tags IS NULL", reader => reader.GetString(0)) .SelectMany(Json.Deserialize>) .Distinct() .ToArray();