From 4eb2c0724ef366823ffb59e4382d9a1eb2617f07 Mon Sep 17 00:00:00 2001 From: nanxun Date: Tue, 18 Aug 2026 00:30:01 +0800 Subject: [PATCH] fix: remove short fragment recovery scan --- .../LiveRoomPollingBackgroundService.cs | 2 - .../ShortFragmentConsolidationService.cs | 50 ------------------- 2 files changed, 52 deletions(-) diff --git a/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs b/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs index 3a7a8b2..ee9f9e3 100644 --- a/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs +++ b/src/LiveRecorder.Infrastructure/Services/LiveRoomPollingBackgroundService.cs @@ -98,8 +98,6 @@ public sealed class LiveRoomPollingBackgroundService : BackgroundService, ILiveR // insufficient to remux, and it is retried every poll cycle. await ffmpegService.ResumePausedFinalizationsAsync(stoppingToken); await ffmpegService.ResumeArtifactRepairsAsync(stoppingToken); - var shortFragmentRecovery = scope.ServiceProvider.GetRequiredService(); - await shortFragmentRecovery.ResumeInterruptedMergesAsync(stoppingToken); if (!settings.EnableBackgroundPolling) { diff --git a/src/LiveRecorder.Infrastructure/Services/ShortFragmentConsolidationService.cs b/src/LiveRecorder.Infrastructure/Services/ShortFragmentConsolidationService.cs index 72a3d4f..b3be867 100644 --- a/src/LiveRecorder.Infrastructure/Services/ShortFragmentConsolidationService.cs +++ b/src/LiveRecorder.Infrastructure/Services/ShortFragmentConsolidationService.cs @@ -108,56 +108,6 @@ public sealed class ShortFragmentConsolidationService : FragmentDispatchDecision.Wait("短分片合并失败,原文件已保留,将自动重试。", TimeSpan.FromMinutes(1)); } - public async Task ResumeInterruptedMergesAsync(CancellationToken cancellationToken) - { - var sources = await _dbContext.RecordTasks - .AsNoTracking() - .Include(item => item.Result) - .Where(item => item.IsHiddenArtifactSource && item.Result != null) - .OrderByDescending(item => item.UpdatedAt) - .Take(100) - .ToListAsync(cancellationToken); - var manifests = new HashSet(StringComparer.OrdinalIgnoreCase); - foreach (var source in sources) - { - var parent = Path.GetDirectoryName(Path.GetFullPath(source.Result!.FilePath)); - var recoveryBase = parent is null ? null : Path.Combine(parent, ".liverecorder-recovery", source.RecordSessionId.ToString("N")); - if (recoveryBase is null || !Directory.Exists(recoveryBase)) continue; - foreach (var path in Directory.EnumerateFiles(recoveryBase, "manifest.json", SearchOption.AllDirectories).Take(100)) manifests.Add(path); - } - - var resumed = 0; - foreach (var path in manifests) - { - try - { - var manifest = JsonSerializer.Deserialize(await File.ReadAllTextAsync(path, cancellationToken)); - if (manifest is null || manifest.Phase == "completed" || string.IsNullOrWhiteSpace(manifest.MergedPath)) continue; - var targetPath = await _dbContext.RecordTasks - .AsNoTracking() - .Where(item => item.Id == manifest.TargetRecordTaskId && item.Result != null) - .Select(item => item.Result!.FilePath) - .FirstOrDefaultAsync(cancellationToken); - if (!File.Exists(manifest.MergedPath) || !string.Equals(Path.GetFullPath(targetPath ?? string.Empty), Path.GetFullPath(manifest.MergedPath), StringComparison.OrdinalIgnoreCase)) continue; - - foreach (var source in manifest.Sources) - { - CopyToRecovery(source.VideoPath, manifest.RecoveryDirectory); - CopyToRecovery(source.DanmakuPath, manifest.RecoveryDirectory); - DeleteOriginal(source.VideoPath, manifest.MergedPath); - DeleteOriginal(source.DanmakuPath, Path.ChangeExtension(manifest.MergedPath, ".xml")); - } - await WriteManifestAsync(manifest.RecoveryDirectory, manifest with { Phase = "completed" }, cancellationToken); - resumed++; - } - catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException) - { - _logger.LogWarning(ex, "Unable to resume short-fragment recovery manifest {ManifestPath}", path); - } - } - return resumed; - } - private static List ResolveMergeGroup(IReadOnlyList tasks, int index) { var durations = tasks