Convert to 'using' declaration in Housekeeping Tasks

Closes #2612
pull/2615/head
Bogdan 2 years ago
parent c710b117ab
commit 60abb298b2

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
if (_database.DatabaseType == DatabaseType.PostgreSQL)
{
mapper.Execute(@"DELETE FROM ""MetadataFiles""
@ -44,5 +43,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}
}

@ -14,13 +14,11 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""NamingConfig""
WHERE ""Id"" NOT IN (
SELECT ""Id"" FROM ""NamingConfig""
LIMIT 1)");
}
}
}
}

@ -14,13 +14,11 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""Users""
WHERE ""Id"" NOT IN (
SELECT ""Id"" FROM ""Users""
LIMIT 1)");
}
}
}
}

@ -21,8 +21,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void DeleteDuplicateAuthorMetadata()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT MIN(""Id"") FROM ""MetadataFiles""
@ -31,12 +30,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
HAVING COUNT(""AuthorId"") > 1
)");
}
}
private void DeleteDuplicateBookMetadata()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT MIN(""Id"") FROM ""MetadataFiles""
@ -45,12 +42,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
HAVING COUNT(""BookId"") > 1
)");
}
}
private void DeleteDuplicateBookFileMetadata()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT MIN(""Id"") FROM ""MetadataFiles""
@ -60,5 +55,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""AuthorMetadata""
WHERE ""Id"" IN (
SELECT ""AuthorMetadata"".""Id"" FROM ""AuthorMetadata""
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Books"".""Id"" IS NULL AND ""Authors"".""Id"" IS NULL)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""Blocklist""
WHERE ""Id"" IN (
SELECT ""Blocklist"".""Id"" FROM ""Blocklist""
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Authors"".""Id"" IS NULL)");
}
}
}
}

@ -14,9 +14,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
// Unlink where track no longer exists
using var mapper = _database.OpenConnection();
// Unlink where books no longer exists
mapper.Execute(@"UPDATE ""BookFiles""
SET ""EditionId"" = 0
WHERE ""Id"" IN (
@ -26,5 +26,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Editions"".""Id"" IS NULL)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""Books""
WHERE ""Id"" IN (
SELECT ""Books"".""Id"" FROM ""Books""
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Authors"".""Id"" IS NULL)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""Editions""
WHERE ""Id"" IN (
SELECT ""Editions"".""Id"" FROM ""Editions""
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Books"".""Id"" IS NULL)");
}
}
}
}

@ -20,8 +20,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void CleanupOrphanedByAuthor()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""History""
WHERE ""Id"" IN (
SELECT ""History"".""Id"" FROM ""History""
@ -29,12 +28,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
ON ""History"".""AuthorId"" = ""Authors"".""Id""
WHERE ""Authors"".""Id"" IS NULL)");
}
}
private void CleanupOrphanedByBook()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""History""
WHERE ""Id"" IN (
SELECT ""History"".""Id"" FROM ""History""
@ -43,5 +40,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Books"".""Id"" IS NULL)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""ImportListStatus""
WHERE ""Id"" IN (
SELECT ""ImportListStatus"".""Id"" FROM ""ImportListStatus""
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""ImportLists"".""Id"" IS NULL)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""IndexerStatus""
WHERE ""Id"" IN (
SELECT ""IndexerStatus"".""Id"" FROM ""IndexerStatus""
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Indexers"".""Id"" IS NULL)");
}
}
}
}

@ -23,8 +23,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void DeleteOrphanedByAuthor()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
@ -32,12 +31,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
ON ""MetadataFiles"".""AuthorId"" = ""Authors"".""Id""
WHERE ""Authors"".""Id"" IS NULL)");
}
}
private void DeleteOrphanedByBook()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
@ -46,12 +43,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""MetadataFiles"".""BookId"" > 0
AND ""Books"".""Id"" IS NULL)");
}
}
private void DeleteOrphanedByTrackFile()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
@ -60,24 +55,20 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""MetadataFiles"".""BookFileId"" > 0
AND ""BookFiles"".""Id"" IS NULL)");
}
}
private void DeleteWhereBookIdIsZero()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""Id"" FROM ""MetadataFiles""
WHERE ""Type"" IN (2, 4)
AND ""BookId"" = 0)");
}
}
private void DeleteWhereTrackFileIsZero()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""Id"" FROM ""MetadataFiles""
@ -85,5 +76,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
AND ""BookFileId"" = 0)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""PendingReleases""
WHERE ""Id"" IN (
SELECT ""PendingReleases"".""Id"" FROM ""PendingReleases""
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Authors"".""Id"" IS NULL)");
}
}
}
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""SeriesBookLink""
WHERE ""Id"" IN (
SELECT ""SeriesBookLink"".""Id"" FROM ""SeriesBookLink""
@ -31,5 +30,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""Series"".""Id"" IS NULL)");
}
}
}
}

@ -18,8 +18,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
var usedTags = new[] { "Authors", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers" }
.SelectMany(v => GetUsedTags(v, mapper))
.Distinct()
@ -43,7 +42,6 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
mapper.Execute("DELETE FROM \"Tags\"");
}
}
}
private int[] GetUsedTags(string table, IDbConnection mapper)
{

@ -24,13 +24,11 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
_logger.Debug("Not running scheduled task last execution cleanup during debug");
}
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"UPDATE ""ScheduledTasks""
SET ""LastExecution"" = @time
WHERE ""LastExecution"" > @time",
new { time = DateTime.UtcNow });
}
}
}
}

Loading…
Cancel
Save