diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs index fca297962..e354c3ddb 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs @@ -18,17 +18,16 @@ public CleanupUnusedTags(IMainDatabase database) public void Clean() { - using (var mapper = _database.OpenConnection()) - { - var usedTags = new[] { "Movies", "Notifications", "DelayProfiles", "Restrictions", "ImportLists", "Indexers" } - .SelectMany(v => GetUsedTags(v, mapper)) - .Distinct() - .ToList(); + var mapper = _database.OpenConnection(); - var usedTagsList = usedTags.Select(d => d.ToString()).Join(","); + var usedTags = new[] { "Movies", "Notifications", "DelayProfiles", "Restrictions", "ImportLists", "Indexers" } + .SelectMany(v => GetUsedTags(v, mapper)) + .Distinct() + .ToList(); - mapper.Execute($"DELETE FROM Tags WHERE NOT Id IN ({usedTagsList})"); - } + var usedTagsList = usedTags.Select(d => d.ToString()).Join(","); + + mapper.Execute($"DELETE FROM Tags WHERE NOT Id IN ({usedTagsList})"); } private int[] GetUsedTags(string table, IDbConnection mapper)