From 96251ee4bbb53ed158a0b54ad2265ebd31ee9b26 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Mon, 23 Mar 2026 11:14:31 +0200 Subject: [PATCH] fix per-instance search count during dry run --- .../General/Controllers/GeneralConfigController.cs | 10 +++++++--- .../Cleanuparr.Infrastructure/Features/Jobs/Seeker.cs | 10 ++++++---- .../Models/State/SeekerHistory.cs | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/code/backend/Cleanuparr.Api/Features/General/Controllers/GeneralConfigController.cs b/code/backend/Cleanuparr.Api/Features/General/Controllers/GeneralConfigController.cs index 62922f84..d987fbdc 100644 --- a/code/backend/Cleanuparr.Api/Features/General/Controllers/GeneralConfigController.cs +++ b/code/backend/Cleanuparr.Api/Features/General/Controllers/GeneralConfigController.cs @@ -80,10 +80,14 @@ public sealed class GeneralConfigController : ControllerBase .Where(d => !d.Strikes.Any()) .ExecuteDeleteAsync(); + var deletedHistory = await _dataContext.SeekerHistory + .Where(h => h.IsDryRun) + .ExecuteDeleteAsync(); + _logger.LogWarning( - "Dry run disabled — purged dry-run data: {Strikes} strikes, {Events} events, {ManualEvents} manual events, {Items} orphaned download items removed", - deletedStrikes, deletedEvents, deletedManualEvents, deletedItems); - + "Dry run disabled — purged dry-run data: {Strikes} strikes, {Events} events, {ManualEvents} manual events, {Items} orphaned download items, {History} search history entries removed", + deletedStrikes, deletedEvents, deletedManualEvents, deletedItems, deletedHistory); + await transaction.CommitAsync(); } catch diff --git a/code/backend/Cleanuparr.Infrastructure/Features/Jobs/Seeker.cs b/code/backend/Cleanuparr.Infrastructure/Features/Jobs/Seeker.cs index 543e9afa..72322f66 100644 --- a/code/backend/Cleanuparr.Infrastructure/Features/Jobs/Seeker.cs +++ b/code/backend/Cleanuparr.Infrastructure/Features/Jobs/Seeker.cs @@ -325,11 +325,11 @@ public sealed class Seeker : IHandler _logger.LogInformation("Searched {Count} items on {InstanceName}: {Items}", searchItems.Count, arrInstance.Name, string.Join(", ", selectedNames)); + // Update search history (always, so stats are accurate during dry run) + await UpdateSearchHistoryAsync(arrInstance.Id, instanceType, instanceConfig.CurrentRunId, historyIds, selectedNames, seasonNumber, isDryRun); + if (!isDryRun) { - // Update search history - await UpdateSearchHistoryAsync(arrInstance.Id, instanceType, instanceConfig.CurrentRunId, historyIds, selectedNames, seasonNumber); - // Track commands long externalItemId = historyIds.FirstOrDefault(); string itemTitle = selectedNames.FirstOrDefault() ?? string.Empty; @@ -635,7 +635,8 @@ public sealed class Seeker : IHandler Guid runId, List searchedIds, List? itemTitles = null, - int seasonNumber = 0) + int seasonNumber = 0, + bool isDryRun = false) { var now = DateTime.UtcNow; @@ -672,6 +673,7 @@ public sealed class Seeker : IHandler RunId = runId, LastSearchedAt = now, ItemTitle = title, + IsDryRun = isDryRun, }); } } diff --git a/code/backend/Cleanuparr.Persistence/Models/State/SeekerHistory.cs b/code/backend/Cleanuparr.Persistence/Models/State/SeekerHistory.cs index 70335f75..d19a2e3c 100644 --- a/code/backend/Cleanuparr.Persistence/Models/State/SeekerHistory.cs +++ b/code/backend/Cleanuparr.Persistence/Models/State/SeekerHistory.cs @@ -60,4 +60,9 @@ public sealed record SeekerHistory /// Running count of how many times this item has been searched /// public int SearchCount { get; set; } = 1; + + /// + /// Whether this history entry was created during a dry run + /// + public bool IsDryRun { get; set; } }