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()
|
public void Clean()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -28,5 +27,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,11 @@ 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
|
||||||
LIMIT 1)");
|
LIMIT 1)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,11 @@ 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
|
||||||
LIMIT 1)");
|
LIMIT 1)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
|
|
||||||
private void DeleteDuplicateSeriesMetadata()
|
private void DeleteDuplicateSeriesMetadata()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -31,12 +30,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
HAVING COUNT(SeriesId) > 1
|
HAVING COUNT(SeriesId) > 1
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void DeleteDuplicateEpisodeMetadata()
|
private void DeleteDuplicateEpisodeMetadata()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -45,12 +42,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
HAVING COUNT(EpisodeFileId) > 1
|
HAVING COUNT(EpisodeFileId) > 1
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void DeleteDuplicateEpisodeImages()
|
private void DeleteDuplicateEpisodeImages()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -60,5 +55,4 @@ 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
|
||||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE Series.Id IS NULL)");
|
WHERE Series.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 EpisodeFiles
|
mapper.Execute(@"DELETE FROM EpisodeFiles
|
||||||
WHERE Id IN (
|
WHERE Id IN (
|
||||||
SELECT EpisodeFiles.Id FROM EpisodeFiles
|
SELECT EpisodeFiles.Id FROM EpisodeFiles
|
||||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE Episodes.Id IS NULL)");
|
WHERE Episodes.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 Episodes
|
mapper.Execute(@"DELETE FROM Episodes
|
||||||
WHERE Id IN (
|
WHERE Id IN (
|
||||||
SELECT Episodes.Id FROM Episodes
|
SELECT Episodes.Id FROM Episodes
|
||||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE Series.Id IS NULL)");
|
WHERE Series.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
|
|
||||||
private void CleanupOrphanedBySeries()
|
private void CleanupOrphanedBySeries()
|
||||||
{
|
{
|
||||||
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.SeriesId = Series.Id
|
ON History.SeriesId = Series.Id
|
||||||
WHERE Series.Id IS NULL)");
|
WHERE Series.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void CleanupOrphanedByEpisode()
|
private void CleanupOrphanedByEpisode()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -43,5 +40,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE Episodes.Id IS NULL)");
|
WHERE Episodes.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE ImportLists.Id IS NULL)");
|
WHERE ImportLists.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE Indexers.Id IS NULL)");
|
WHERE Indexers.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
|
|
||||||
private void DeleteOrphanedBySeries()
|
private void DeleteOrphanedBySeries()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -30,12 +29,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
ON MetadataFiles.SeriesId = Series.Id
|
ON MetadataFiles.SeriesId = Series.Id
|
||||||
WHERE Series.Id IS NULL)");
|
WHERE Series.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void DeleteOrphanedByEpisodeFile()
|
private void DeleteOrphanedByEpisodeFile()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -44,12 +41,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE MetadataFiles.EpisodeFileId > 0
|
WHERE MetadataFiles.EpisodeFileId > 0
|
||||||
AND EpisodeFiles.Id IS NULL)");
|
AND EpisodeFiles.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void DeleteWhereEpisodeFileIsZero()
|
private void DeleteWhereEpisodeFileIsZero()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -57,5 +52,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
AND EpisodeFileId = 0)");
|
AND EpisodeFileId = 0)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
@ -24,5 +23,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE Series.Id IS NULL)");
|
WHERE Series.Id IS NULL)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,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[] { "Series", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers", "AutoTagging" }
|
var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers", "AutoTagging" }
|
||||||
.SelectMany(v => GetUsedTags(v, mapper))
|
.SelectMany(v => GetUsedTags(v, mapper))
|
||||||
.Distinct()
|
.Distinct()
|
||||||
|
@ -28,7 +27,6 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
|
|
||||||
mapper.Execute($"DELETE FROM Tags WHERE NOT Id IN ({usedTagsList})");
|
mapper.Execute($"DELETE FROM Tags WHERE NOT Id IN ({usedTagsList})");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private int[] GetUsedTags(string table, IDbConnection mapper)
|
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");
|
_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",
|
||||||
new { time = DateTime.UtcNow });
|
new { time = DateTime.UtcNow });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue