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() public void Clean()
{ {
using (var mapper = _database.OpenConnection()) using var mapper = _database.OpenConnection();
{
if (_database.DatabaseType == DatabaseType.PostgreSQL) if (_database.DatabaseType == DatabaseType.PostgreSQL)
{ {
mapper.Execute(@"DELETE FROM ""MetadataFiles"" mapper.Execute(@"DELETE FROM ""MetadataFiles""
@ -45,4 +44,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
} }
} }
} }
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean() public void Clean()
{ {
using (var mapper = _database.OpenConnection()) using var mapper = _database.OpenConnection();
{
mapper.Execute(@"DELETE FROM ""NamingConfig"" mapper.Execute(@"DELETE FROM ""NamingConfig""
WHERE ""Id"" NOT IN ( WHERE ""Id"" NOT IN (
SELECT ""Id"" FROM ""NamingConfig"" SELECT ""Id"" FROM ""NamingConfig""
@ -23,4 +22,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
} }
} }
} }
}

@ -14,8 +14,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean() public void Clean()
{ {
using (var mapper = _database.OpenConnection()) using var mapper = _database.OpenConnection();
{
mapper.Execute(@"DELETE FROM ""Users"" mapper.Execute(@"DELETE FROM ""Users""
WHERE ""Id"" NOT IN ( WHERE ""Id"" NOT IN (
SELECT ""Id"" FROM ""Users"" SELECT ""Id"" FROM ""Users""
@ -23,4 +22,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
} }
} }
} }
}

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -24,8 +24,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
_logger.Debug("Not running scheduled task last execution cleanup during debug"); _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"" mapper.Execute(@"UPDATE ""ScheduledTasks""
SET ""LastExecution"" = @time SET ""LastExecution"" = @time
WHERE ""LastExecution"" > @time", WHERE ""LastExecution"" > @time",
@ -33,4 +32,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
} }
} }
} }
}

Loading…
Cancel
Save