Convert to 'using' declaration in Housekeeping Tasks

Closes #8723
pull/8726/head
Bogdan 2 years ago
parent d008768fff
commit 41492efd2e

@ -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""
@ -45,4 +44,3 @@ 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 ""NamingConfig""
WHERE ""Id"" NOT IN (
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()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""Users""
WHERE ""Id"" NOT IN (
SELECT ""Id"" FROM ""Users""
@ -23,4 +22,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

@ -16,8 +16,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 ""PendingReleases""
@ -43,4 +42,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

@ -20,8 +20,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void DeleteDuplicateMovieMetadata()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT MIN(""Id"") FROM ""MetadataFiles""
@ -30,12 +29,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
HAVING COUNT(""MovieId"") > 1
)");
}
}
private void DeleteDuplicateMovieFileMetadata()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT MIN(""Id"") FROM ""MetadataFiles""
@ -46,4 +43,3 @@ 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 ""AlternativeTitles""
WHERE ""Id"" IN (
SELECT ""AlternativeTitles"".""Id"" FROM ""AlternativeTitles""
@ -25,4 +24,3 @@ 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 ""Blocklist""
WHERE ""Id"" IN (
SELECT ""Blocklist"".""Id"" FROM ""Blocklist""
@ -25,4 +24,3 @@ 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 ""Collections"" WHERE ""TmdbId"" IN (SELECT ""X"".""TmdbId"" FROM (SELECT ""Collections"".""TmdbId"", COUNT(""Movies"".""Id"") as ""MovieCount"" FROM ""Collections""
LEFT OUTER JOIN ""MovieMetadata"" ON ""Collections"".""TmdbId"" = ""MovieMetadata"".""CollectionTmdbId""
LEFT OUTER JOIN ""Movies"" ON ""Movies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
@ -23,4 +22,3 @@ 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 ""Credits""
WHERE ""Id"" IN (
SELECT ""Credits"".""Id"" FROM ""Credits""
@ -25,4 +24,3 @@ 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 ""DownloadClientStatus""
WHERE ""Id"" IN (
SELECT ""DownloadClientStatus"".""Id"" FROM ""DownloadClientStatus""
@ -25,4 +24,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

@ -20,8 +20,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void DeleteOrphanedByMovie()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""ExtraFiles""
WHERE ""Id"" IN (
SELECT ""ExtraFiles"".""Id"" FROM ""ExtraFiles""
@ -29,12 +28,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
ON ""ExtraFiles"".""MovieId"" = ""Movies"".""Id""
WHERE ""Movies"".""Id"" IS NULL)");
}
}
private void DeleteOrphanedByMovieFile()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""ExtraFiles""
WHERE ""Id"" IN (
SELECT ""ExtraFiles"".""Id"" FROM ""ExtraFiles""
@ -45,4 +42,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

@ -19,8 +19,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void CleanupOrphanedByMovie()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""History""
WHERE ""Id"" IN (
SELECT ""History"".""Id"" FROM ""History""
@ -30,4 +29,3 @@ 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 ""IndexerStatus""
WHERE ""Id"" IN (
SELECT ""IndexerStatus"".""Id"" FROM ""IndexerStatus""
@ -25,4 +24,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

@ -21,8 +21,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void DeleteOrphanedByMovie()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
@ -30,12 +29,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
ON ""MetadataFiles"".""MovieId"" = ""Movies"".""Id""
WHERE ""Movies"".""Id"" IS NULL)");
}
}
private void DeleteOrphanedByMovieFile()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
@ -44,12 +41,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE ""MetadataFiles"".""MovieFileId"" > 0
AND ""MovieFiles"".""Id"" IS NULL)");
}
}
private void DeleteWhereMovieFileIsZero()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""MetadataFiles""
WHERE ""Id"" IN (
SELECT ""Id"" FROM ""MetadataFiles""
@ -58,4 +53,3 @@ 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 ""MovieFiles""
WHERE ""Id"" IN (
SELECT ""MovieFiles"".""Id"" FROM ""MovieFiles""
@ -25,4 +24,3 @@ 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 ""MovieMetadata""
WHERE ""Id"" IN (
SELECT ""MovieMetadata"".""Id"" FROM ""MovieMetadata""
@ -26,4 +25,3 @@ 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(@"UPDATE ""Movies""
SET ""MovieFileId"" = 0
WHERE ""Id"" IN (
@ -26,4 +25,3 @@ 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 ""MovieTranslations""
WHERE ""Id"" IN (
SELECT ""MovieTranslations"".""Id"" FROM ""MovieTranslations""
@ -25,4 +24,3 @@ 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 ""PendingReleases""
WHERE ""Id"" IN (
SELECT ""PendingReleases"".""Id"" FROM ""PendingReleases""
@ -25,4 +24,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

@ -20,8 +20,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void DeleteOrphanedByMovie()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""SubtitleFiles""
WHERE ""Id"" IN (
SELECT ""SubtitleFiles"".""Id"" FROM ""SubtitleFiles""
@ -29,12 +28,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
ON ""SubtitleFiles"".""MovieId"" = ""Movies"".""Id""
WHERE ""Movies"".""Id"" IS NULL)");
}
}
private void DeleteOrphanedByMovieFile()
{
using (var mapper = _database.OpenConnection())
{
using var mapper = _database.OpenConnection();
mapper.Execute(@"DELETE FROM ""SubtitleFiles""
WHERE ""Id"" IN (
SELECT ""SubtitleFiles"".""Id"" FROM ""SubtitleFiles""
@ -45,4 +42,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

@ -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[] { "Movies", "Notifications", "DelayProfiles", "Restrictions", "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,8 +24,7 @@ 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",
@ -33,4 +32,3 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
}
}
}
}

Loading…
Cancel
Save