Convert to 'using' declaration in Housekeeping Tasks

pull/1672/head
Bogdan 1 year ago
parent a3ccc3d0cf
commit d21debe77f

@ -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)");
}
} }
} }
} }

@ -19,15 +19,13 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
private void CleanupOrphanedByIndexer() private void CleanupOrphanedByIndexer()
{ {
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"" LEFT OUTER JOIN ""Indexers""
LEFT OUTER JOIN ""Indexers"" ON ""History"".""IndexerId"" = ""Indexers"".""Id""
ON ""History"".""IndexerId"" = ""Indexers"".""Id"" WHERE ""Indexers"".""Id"" IS NULL)");
WHERE ""Indexers"".""Id"" IS NULL)");
}
} }
} }
} }

@ -14,15 +14,13 @@ 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"" LEFT OUTER JOIN ""Indexers""
LEFT OUTER JOIN ""Indexers"" ON ""IndexerStatus"".""ProviderId"" = ""Indexers"".""Id""
ON ""IndexerStatus"".""ProviderId"" = ""Indexers"".""Id"" WHERE ""Indexers"".""Id"" IS NULL)");
WHERE ""Indexers"".""Id"" IS NULL)");
}
} }
} }
} }

@ -17,23 +17,21 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
public void Clean() public void Clean()
{ {
using (var mapper = _database.OpenConnection()) using var mapper = _database.OpenConnection();
{ var usedTags = new[] { "Notifications", "IndexerProxies", "Indexers", "Applications" }
var usedTags = new[] { "Notifications", "IndexerProxies", "Indexers", "Applications" } .SelectMany(v => GetUsedTags(v, mapper))
.SelectMany(v => GetUsedTags(v, mapper)) .Distinct()
.Distinct() .ToArray();
.ToArray();
if (usedTags.Length > 0) if (usedTags.Length > 0)
{ {
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})");
} }
else else
{ {
mapper.Execute($"DELETE FROM \"Tags\""); mapper.Execute("DELETE FROM \"Tags\"");
}
} }
} }

@ -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…
Cancel
Save