Convert to 'using' declaration in Housekeeping Tasks
This commit is contained in:
parent
9af6d1b9d9
commit
82919a8ed1
|
@ -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 MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
|
@ -28,5 +27,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 DeleteDuplicateSeriesMetadata()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
|
@ -31,12 +30,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
HAVING COUNT(SeriesId) > 1
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteDuplicateEpisodeMetadata()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
|
@ -45,12 +42,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
HAVING COUNT(EpisodeFileId) > 1
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteDuplicateEpisodeImages()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT 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 Blocklist
|
||||
WHERE Id IN (
|
||||
SELECT Blocklist.Id FROM Blocklist
|
||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
WHERE Series.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 EpisodeFiles
|
||||
WHERE Id IN (
|
||||
SELECT EpisodeFiles.Id FROM EpisodeFiles
|
||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
WHERE Episodes.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 Episodes
|
||||
WHERE Id IN (
|
||||
SELECT Episodes.Id FROM Episodes
|
||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
private void CleanupOrphanedBySeries()
|
||||
{
|
||||
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.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanupOrphanedByEpisode()
|
||||
{
|
||||
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 Episodes.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)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
private void DeleteOrphanedBySeries()
|
||||
{
|
||||
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.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteOrphanedByEpisodeFile()
|
||||
{
|
||||
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.EpisodeFileId > 0
|
||||
AND EpisodeFiles.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteWhereEpisodeFileIsZero()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
|
@ -57,5 +52,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
AND EpisodeFileId = 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 Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
using var mapper = _database.OpenConnection();
|
||||
var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers", "AutoTagging" }
|
||||
.SelectMany(v => GetUsedTags(v, mapper))
|
||||
.Distinct()
|
||||
|
@ -28,7 +27,6 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
mapper.Execute($"DELETE FROM Tags WHERE NOT Id IN ({usedTagsList})");
|
||||
}
|
||||
}
|
||||
|
||||
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…
Reference in New Issue