You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|
|
|
|
{
|
|
|
|
|
public class CleanupDuplicateMetadataFiles : IHousekeepingTask
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public CleanupDuplicateMetadataFiles(IDatabase database, Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clean()
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Running cleanup of duplicate metadata files");
|
|
|
|
|
|
|
|
|
|
DeleteDuplicateSeriesMetadata();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteDuplicateSeriesMetadata()
|
|
|
|
|
{
|
|
|
|
|
var mapper = _database.GetDataMapper();
|
|
|
|
|
|
|
|
|
|
mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles
|
|
|
|
|
WHERE Id IN (
|
|
|
|
|
SELECT Id FROM MetadataFiles
|
|
|
|
|
WHERE Type = 1
|
|
|
|
|
GROUP BY SeriesId, Consumer
|
|
|
|
|
HAVING COUNT(SeriesId) > 1
|
|
|
|
|
)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|