Convert to 'using' declaration in Housekeeping Tasks
This commit is contained in:
parent
9af6d1b9d9
commit
82919a8ed1
|
@ -14,19 +14,17 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE RelativePath
|
||||
LIKE '_:\%'
|
||||
OR RelativePath
|
||||
LIKE '\%'
|
||||
OR RelativePath
|
||||
LIKE '/%'
|
||||
)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE RelativePath
|
||||
LIKE '_:\%'
|
||||
OR RelativePath
|
||||
LIKE '\%'
|
||||
OR RelativePath
|
||||
LIKE '/%'
|
||||
)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,11 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM NamingConfig
|
||||
WHERE ID NOT IN (
|
||||
SELECT ID FROM NamingConfig
|
||||
LIMIT 1)");
|
||||
}
|
||||
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())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM Users
|
||||
WHERE ID NOT IN (
|
||||
SELECT ID FROM Users
|
||||
LIMIT 1)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM Users
|
||||
WHERE ID NOT IN (
|
||||
SELECT ID FROM Users
|
||||
LIMIT 1)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,44 +21,38 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
private void DeleteDuplicateSeriesMetadata()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type = 1
|
||||
GROUP BY SeriesId, Consumer
|
||||
HAVING COUNT(SeriesId) > 1
|
||||
)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type = 1
|
||||
GROUP BY SeriesId, Consumer
|
||||
HAVING COUNT(SeriesId) > 1
|
||||
)");
|
||||
}
|
||||
|
||||
private void DeleteDuplicateEpisodeMetadata()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type = 2
|
||||
GROUP BY EpisodeFileId, Consumer
|
||||
HAVING COUNT(EpisodeFileId) > 1
|
||||
)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type = 2
|
||||
GROUP BY EpisodeFileId, Consumer
|
||||
HAVING COUNT(EpisodeFileId) > 1
|
||||
)");
|
||||
}
|
||||
|
||||
private void DeleteDuplicateEpisodeImages()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type = 5
|
||||
GROUP BY EpisodeFileId, Consumer
|
||||
HAVING COUNT(EpisodeFileId) > 1
|
||||
)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type = 5
|
||||
GROUP BY EpisodeFileId, Consumer
|
||||
HAVING COUNT(EpisodeFileId) > 1
|
||||
)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,13 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM Blocklist
|
||||
WHERE Id IN (
|
||||
SELECT Blocklist.Id FROM Blocklist
|
||||
LEFT OUTER JOIN Series
|
||||
ON Blocklist.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM Blocklist
|
||||
WHERE Id IN (
|
||||
SELECT Blocklist.Id FROM Blocklist
|
||||
LEFT OUTER JOIN Series
|
||||
ON Blocklist.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,13 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM EpisodeFiles
|
||||
WHERE Id IN (
|
||||
SELECT EpisodeFiles.Id FROM EpisodeFiles
|
||||
LEFT OUTER JOIN Episodes
|
||||
ON EpisodeFiles.Id = Episodes.EpisodeFileId
|
||||
WHERE Episodes.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM EpisodeFiles
|
||||
WHERE Id IN (
|
||||
SELECT EpisodeFiles.Id FROM EpisodeFiles
|
||||
LEFT OUTER JOIN Episodes
|
||||
ON EpisodeFiles.Id = Episodes.EpisodeFileId
|
||||
WHERE Episodes.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,13 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM Episodes
|
||||
WHERE Id IN (
|
||||
SELECT Episodes.Id FROM Episodes
|
||||
LEFT OUTER JOIN Series
|
||||
ON Episodes.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM Episodes
|
||||
WHERE Id IN (
|
||||
SELECT Episodes.Id FROM Episodes
|
||||
LEFT OUTER JOIN Series
|
||||
ON Episodes.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,28 +20,24 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
private void CleanupOrphanedBySeries()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM History
|
||||
WHERE Id IN (
|
||||
SELECT History.Id FROM History
|
||||
LEFT OUTER JOIN Series
|
||||
ON History.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM History
|
||||
WHERE Id IN (
|
||||
SELECT History.Id FROM History
|
||||
LEFT OUTER JOIN Series
|
||||
ON History.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
|
||||
private void CleanupOrphanedByEpisode()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM History
|
||||
WHERE Id IN (
|
||||
SELECT History.Id FROM History
|
||||
LEFT OUTER JOIN Episodes
|
||||
ON History.EpisodeId = Episodes.Id
|
||||
WHERE Episodes.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM History
|
||||
WHERE Id IN (
|
||||
SELECT History.Id FROM History
|
||||
LEFT OUTER JOIN Episodes
|
||||
ON History.EpisodeId = Episodes.Id
|
||||
WHERE Episodes.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,13 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ImportListStatus
|
||||
WHERE Id IN (
|
||||
SELECT ImportListStatus.Id FROM ImportListStatus
|
||||
LEFT OUTER JOIN ImportLists
|
||||
ON ImportListStatus.ProviderId = ImportLists.Id
|
||||
WHERE ImportLists.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ImportListStatus
|
||||
WHERE Id IN (
|
||||
SELECT ImportListStatus.Id FROM ImportListStatus
|
||||
LEFT OUTER JOIN ImportLists
|
||||
ON ImportListStatus.ProviderId = ImportLists.Id
|
||||
WHERE ImportLists.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,13 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM IndexerStatus
|
||||
WHERE Id IN (
|
||||
SELECT IndexerStatus.Id FROM IndexerStatus
|
||||
LEFT OUTER JOIN Indexers
|
||||
ON IndexerStatus.ProviderId = Indexers.Id
|
||||
WHERE Indexers.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM IndexerStatus
|
||||
WHERE Id IN (
|
||||
SELECT IndexerStatus.Id FROM IndexerStatus
|
||||
LEFT OUTER JOIN Indexers
|
||||
ON IndexerStatus.ProviderId = Indexers.Id
|
||||
WHERE Indexers.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,41 +21,35 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
private void DeleteOrphanedBySeries()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT MetadataFiles.Id FROM MetadataFiles
|
||||
LEFT OUTER JOIN Series
|
||||
ON MetadataFiles.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT MetadataFiles.Id FROM MetadataFiles
|
||||
LEFT OUTER JOIN Series
|
||||
ON MetadataFiles.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
|
||||
private void DeleteOrphanedByEpisodeFile()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT MetadataFiles.Id FROM MetadataFiles
|
||||
LEFT OUTER JOIN EpisodeFiles
|
||||
ON MetadataFiles.EpisodeFileId = EpisodeFiles.Id
|
||||
WHERE MetadataFiles.EpisodeFileId > 0
|
||||
AND EpisodeFiles.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT MetadataFiles.Id FROM MetadataFiles
|
||||
LEFT OUTER JOIN EpisodeFiles
|
||||
ON MetadataFiles.EpisodeFileId = EpisodeFiles.Id
|
||||
WHERE MetadataFiles.EpisodeFileId > 0
|
||||
AND EpisodeFiles.Id IS NULL)");
|
||||
}
|
||||
|
||||
private void DeleteWhereEpisodeFileIsZero()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type IN (2, 5)
|
||||
AND EpisodeFileId = 0)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type IN (2, 5)
|
||||
AND EpisodeFileId = 0)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,13 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM PendingReleases
|
||||
WHERE Id IN (
|
||||
SELECT PendingReleases.Id FROM PendingReleases
|
||||
LEFT OUTER JOIN Series
|
||||
ON PendingReleases.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM PendingReleases
|
||||
WHERE Id IN (
|
||||
SELECT PendingReleases.Id FROM PendingReleases
|
||||
LEFT OUTER JOIN Series
|
||||
ON PendingReleases.SeriesId = Series.Id
|
||||
WHERE Series.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,15 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers", "AutoTagging" }
|
||||
.SelectMany(v => GetUsedTags(v, mapper))
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
using var mapper = _database.OpenConnection();
|
||||
var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers", "AutoTagging" }
|
||||
.SelectMany(v => GetUsedTags(v, mapper))
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
||||
var usedTagsList = string.Join(",", usedTags.Select(d => d.ToString()).ToArray());
|
||||
var usedTagsList = string.Join(",", usedTags.Select(d => d.ToString()).ToArray());
|
||||
|
||||
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)
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
mapper.Execute(@"UPDATE ScheduledTasks
|
||||
SET LastExecution = @time
|
||||
WHERE LastExecution > @time",
|
||||
new { time = DateTime.UtcNow });
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"UPDATE ScheduledTasks
|
||||
SET LastExecution = @time
|
||||
WHERE LastExecution > @time",
|
||||
new { time = DateTime.UtcNow });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue