From 47b53a49a9d5212ae1e176c770ae6290c1f2c124 Mon Sep 17 00:00:00 2001 From: spelech <28486500+spelech@users.noreply.github.com> Date: Sun, 20 Sep 2026 14:58:49 +0000 Subject: [PATCH 1/2] Optimize sequential file reading in audio workflows endpoint Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- Endpoints/WorkflowEndpoints.cs | 76 +++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/Endpoints/WorkflowEndpoints.cs b/Endpoints/WorkflowEndpoints.cs index 81b0422..9aebe86 100644 --- a/Endpoints/WorkflowEndpoints.cs +++ b/Endpoints/WorkflowEndpoints.cs @@ -352,54 +352,74 @@ public static void MapWorkflowEndpoints(this WebApplication app) var list = new List(); var seenIds = new HashSet(StringComparer.OrdinalIgnoreCase); + var fileTasks = new List>(); + foreach (var dir in searchDirs) { foreach (var f in Directory.GetFiles(dir, "*.json")) { var id = Path.GetFileNameWithoutExtension(f); - if (seenIds.Contains(id)) continue; - try + async Task<(string, string, object)> ProcessFileAsync(string fileDir, string filePath, string fileId) { - var jsonStr = await File.ReadAllTextAsync(f); - var node = JsonNode.Parse(jsonStr); - var name = node?["name"]?.ToString() ?? id.Replace('_', ' '); - var type = node?["type"]?.ToString() ?? "audio"; - var description = node?["description"]?.ToString() ?? ""; - - if (dir == audioWorkflowsDir || type.Equals("audio", StringComparison.OrdinalIgnoreCase)) + try { - seenIds.Add(id); - list.Add(new + var jsonStr = await File.ReadAllTextAsync(filePath); + var node = JsonNode.Parse(jsonStr); + var name = node?["name"]?.ToString() ?? fileId.Replace('_', ' '); + var type = node?["type"]?.ToString() ?? "audio"; + var description = node?["description"]?.ToString() ?? ""; + + if (fileDir == audioWorkflowsDir || type.Equals("audio", StringComparison.OrdinalIgnoreCase)) { - id, - name, - filename = Path.GetFileName(f), - path = f, - type, - description - }); + return (fileDir, fileId, new + { + id = fileId, + name, + filename = Path.GetFileName(filePath), + path = filePath, + type, + description + }); + } } - } - catch - { - if (seenIds.Add(id)) + catch { - list.Add(new + return (fileDir, fileId, new { - id, - name = id.Replace('_', ' '), - filename = Path.GetFileName(f), - path = f, + id = fileId, + name = fileId.Replace('_', ' '), + filename = Path.GetFileName(filePath), + path = filePath, type = "audio", description = "" }); } + + return (fileDir, fileId, null); } + + fileTasks.Add(ProcessFileAsync(dir, f, id)); } } - return Results.Ok(list); + var processedFiles = await Task.WhenAll(fileTasks); + + foreach (var dir in searchDirs) + { + var dirResults = processedFiles.Where(r => r.dir == dir && r.result != null); + foreach (var res in dirResults) + { + if (seenIds.Add(res.id)) + { + list.Add(res.result); + } + } + } + + var sortedList = list.OrderBy(x => ((dynamic)x).name.ToString()).ToList(); + + return Results.Ok(sortedList); }); app.MapPost("/api/audio/generate", async (AudioGenerateRequest request, ISettingsService settingsService, IHttpClientFactory clientFactory) => From 9da84bfc52ae59ddffc4e6f1230a00d2fb83f14a Mon Sep 17 00:00:00 2001 From: Steven Pelech Date: Sun, 20 Sep 2026 10:03:41 -0500 Subject: [PATCH 2/2] fix: resolve CS8619 nullability warning in ProcessFileAsync --- Endpoints/WorkflowEndpoints.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Endpoints/WorkflowEndpoints.cs b/Endpoints/WorkflowEndpoints.cs index 9aebe86..94e9510 100644 --- a/Endpoints/WorkflowEndpoints.cs +++ b/Endpoints/WorkflowEndpoints.cs @@ -352,7 +352,7 @@ public static void MapWorkflowEndpoints(this WebApplication app) var list = new List(); var seenIds = new HashSet(StringComparer.OrdinalIgnoreCase); - var fileTasks = new List>(); + var fileTasks = new List>(); foreach (var dir in searchDirs) { @@ -360,7 +360,7 @@ public static void MapWorkflowEndpoints(this WebApplication app) { var id = Path.GetFileNameWithoutExtension(f); - async Task<(string, string, object)> ProcessFileAsync(string fileDir, string filePath, string fileId) + async Task<(string, string, object?)> ProcessFileAsync(string fileDir, string filePath, string fileId) { try {