parent
652fdae7d9
commit
fa25324463
@ -0,0 +1,28 @@
|
||||
using Dapper;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||
{
|
||||
public class CleanupOrphanedEditions : IHousekeepingTask
|
||||
{
|
||||
private readonly IMainDatabase _database;
|
||||
|
||||
public CleanupOrphanedEditions(IMainDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM Editions
|
||||
WHERE Id IN (
|
||||
SELECT Editions.Id FROM Editions
|
||||
LEFT OUTER JOIN Books
|
||||
ON Editions.BookId = Books.Id
|
||||
WHERE Books.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using Dapper;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||
{
|
||||
public class CleanupOrphanedSeriesBookLinks : IHousekeepingTask
|
||||
{
|
||||
private readonly IMainDatabase _database;
|
||||
|
||||
public CleanupOrphanedSeriesBookLinks(IMainDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM SeriesBookLinks
|
||||
WHERE Id IN (
|
||||
SELECT SeriesBookLinks.Id FROM SeriesBookLinks
|
||||
LEFT OUTER JOIN Books
|
||||
ON SeriesBookLinks.BookId = Books.Id
|
||||
WHERE Books.Id IS NULL)");
|
||||
|
||||
mapper.Execute(@"DELETE FROM SeriesBookLinks
|
||||
WHERE Id IN (
|
||||
SELECT SeriesBookLinks.Id FROM SeriesBookLinks
|
||||
LEFT OUTER JOIN Series
|
||||
ON SeriesBookLinks.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue