Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Optimized background health checks for newly ignored file types.

nzbdav-devff310028fc70
diff --git a/backend/Config/ConfigManager.cs b/backend/Config/ConfigManager.cs
index 42c23281..f622500f 100644
--- a/backend/Config/ConfigManager.cs
+++ b/backend/Config/ConfigManager.cs
@@ -194,10 +194,15 @@ public class ConfigManager
return GetConfigValue("api.duplicate-nzb-behavior") ?? defaultValue;
}
- public string GetDownloadExtensionBlacklist()
+ public HashSet<string> GetBlacklistedExtensions()
{
var defaultValue = ".nfo, .par2, .sfv";
- return GetConfigValue("api.download-extension-blacklist") ?? defaultValue;
+ return (GetConfigValue("api.download-extension-blacklist") ?? defaultValue)
+ .Split(',', StringSplitOptions.RemoveEmptyEntries)
+ .Select(x => x.Trim())
+ .Where(x => !string.IsNullOrWhiteSpace(x))
+ .Select(x => x.ToLower())
+ .ToHashSet();
}
public class ConfigEventArgs : EventArgs
diff --git a/backend/Queue/PostProcessors/BlacklistedExtensionPostProcessor.cs b/backend/Queue/PostProcessors/BlacklistedExtensionPostProcessor.cs
index a5e56b83..2bb6ae10 100644
--- a/backend/Queue/PostProcessors/BlacklistedExtensionPostProcessor.cs
+++ b/backend/Queue/PostProcessors/BlacklistedExtensionPostProcessor.cs
@@ -10,7 +10,7 @@ public class BlacklistedExtensionPostProcessor(ConfigManager configManager, DavD
{
public void RemoveBlacklistedExtensions()
{
- var blacklistedExtensions = GetBlacklistedExtensions();
+ var blacklistedExtensions = configManager.GetBlacklistedExtensions();
var blacklistedFiles = dbClient.Ctx.ChangeTracker.Entries<DavItem>()
.Where(x => x.State == EntityState.Added)
.Select(x => x.Entity)
@@ -21,16 +21,6 @@ public class BlacklistedExtensionPostProcessor(ConfigManager configManager, DavD
RemoveBlacklistedFile(blacklistedFile);
}
- private HashSet<string> GetBlacklistedExtensions()
- {
- return configManager.GetDownloadExtensionBlacklist()
- .Split(',', StringSplitOptions.RemoveEmptyEntries)
- .Select(x => x.Trim())
- .Where(x => !string.IsNullOrWhiteSpace(x))
- .Select(x => x.ToLower())
- .ToHashSet();
- }
-
private void RemoveBlacklistedFile(DavItem davItem)
{
if (davItem.Type == DavItem.ItemType.NzbFile)
diff --git a/backend/Services/HealthCheckService.cs b/backend/Services/HealthCheckService.cs
index 03f12068..1d875b12 100644
--- a/backend/Services/HealthCheckService.cs
+++ b/backend/Services/HealthCheckService.cs
@@ -201,10 +201,33 @@ public class HealthCheckService
{
try
{
- var symlink = OrganizedSymlinksUtil.GetSymlink(davItem, _configManager);
+ // if the file extension has been marked as ignored,
+ // then don't bother trying to repair it. We can simply delete it.
+ var blacklistedExtensions = _configManager.GetBlacklistedExtensions();
+ if (blacklistedExtensions.Contains(Path.GetExtension(davItem.Name)))
+ {
+ dbClient.Ctx.Items.Remove(davItem);
+ dbClient.Ctx.HealthCheckResults.Add(SendStatus(new HealthCheckResult()
+ {
+ Id = Guid.NewGuid(),
+ DavItemId = davItem.Id,
+ Path = davItem.Path,
+ CreatedAt = DateTimeOffset.UtcNow,
+ Result = HealthCheckResult.HealthResult.Unhealthy,
+ RepairStatus = HealthCheckResult.RepairAction.Deleted,
+ Message = string.Join(" ", [
+ "File had missing articles.",
+ "File extension is marked in settings as ignored (unwanted) file type.",
+ "Deleted file."
+ ])
+ }));
+ await dbClient.Ctx.SaveChangesAsync(ct);
+ return;
+ }
// if the unhealthy item is unlinked/orphaned,
// then we can simply delete it.
+ var symlink = OrganizedSymlinksUtil.GetSymlink(davItem, _configManager);
if (symlink == null)
{
dbClient.Ctx.Items.Remove(davItem);
@@ -217,7 +240,7 @@ public class HealthCheckService
Result = HealthCheckResult.HealthResult.Unhealthy,
RepairStatus = HealthCheckResult.RepairAction.Deleted,
Message = string.Join(" ", [
- "File had missing articles",
+ "File had missing articles.",
"Could not find corresponding symlink within Library Dir.",
"Deleted file."
])