Fixed: Cleanup of unused tags for Import lists.

Fixes #4610
This commit is contained in:
Taloth Saldono 2021-08-06 01:34:26 +02:00
parent 3fb5f65f08
commit 2f6409226a
1 changed files with 5 additions and 4 deletions

View File

@ -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<List<int>>)
.Distinct()
.ToArray();