aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Migrations
diff options
context:
space:
mode:
authorJPVenson <github@jpb.email>2025-06-04 00:15:04 +0300
committerGitHub <noreply@github.com>2025-06-03 15:15:04 -0600
commit9456d7168f64a30513922f8077f0a61c8b751d2e (patch)
treeae76a80be0a7207497763e7d2b3f9c89638f0910 /Jellyfin.Server/Migrations
parentae5e6431c5aa7bb7f8324256878ddbc1136b8b77 (diff)
Add partition helper (#14039)
Diffstat (limited to 'Jellyfin.Server/Migrations')
-rw-r--r--Jellyfin.Server/Migrations/Routines/MoveExtractedFiles.cs52
1 files changed, 23 insertions, 29 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/MoveExtractedFiles.cs b/Jellyfin.Server/Migrations/Routines/MoveExtractedFiles.cs
index 8b4abdfe5..38952eec9 100644
--- a/Jellyfin.Server/Migrations/Routines/MoveExtractedFiles.cs
+++ b/Jellyfin.Server/Migrations/Routines/MoveExtractedFiles.cs
@@ -8,13 +8,14 @@ using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Database.Implementations;
using Jellyfin.Database.Implementations.Entities;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.IO;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
@@ -25,9 +26,7 @@ namespace Jellyfin.Server.Migrations.Routines;
/// Migration to move extracted files to the new directories.
/// </summary>
[JellyfinMigration("2025-04-20T21:00:00", nameof(MoveExtractedFiles))]
-#pragma warning disable CS0618 // Type or member is obsolete
-public class MoveExtractedFiles : IMigrationRoutine
-#pragma warning restore CS0618 // Type or member is obsolete
+public class MoveExtractedFiles : IAsyncMigrationRoutine
{
private readonly IApplicationPaths _appPaths;
private readonly ILogger<MoveExtractedFiles> _logger;
@@ -62,10 +61,10 @@ public class MoveExtractedFiles : IMigrationRoutine
private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments");
/// <inheritdoc />
- public void Perform()
+ public async Task PerformAsync(CancellationToken cancellationToken)
{
const int Limit = 5000;
- int itemCount = 0, offset = 0;
+ int itemCount = 0;
var sw = Stopwatch.StartNew();
@@ -76,32 +75,27 @@ public class MoveExtractedFiles : IMigrationRoutine
// Make sure directories exist
Directory.CreateDirectory(SubtitleCachePath);
Directory.CreateDirectory(AttachmentCachePath);
- do
- {
- var results = context.BaseItems
- .Include(e => e.MediaStreams!.Where(s => s.StreamType == MediaStreamTypeEntity.Subtitle && !s.IsExternal))
- .Where(b => b.MediaType == MediaType.Video.ToString() && !b.IsVirtualItem && !b.IsFolder)
- .OrderBy(e => e.Id)
- .Skip(offset)
- .Take(Limit)
- .Select(b => new Tuple<Guid, string?, ICollection<MediaStreamInfo>?>(b.Id, b.Path, b.MediaStreams)).ToList();
-
- foreach (var result in results)
- {
- if (MoveSubtitleAndAttachmentFiles(result.Item1, result.Item2, result.Item3, context))
- {
- itemCount++;
- }
- }
- offset += Limit;
- if (offset > records)
+ await foreach (var result in context.BaseItems
+ .Include(e => e.MediaStreams!.Where(s => s.StreamType == MediaStreamTypeEntity.Subtitle && !s.IsExternal))
+ .Where(b => b.MediaType == MediaType.Video.ToString() && !b.IsVirtualItem && !b.IsFolder)
+ .Select(b => new
+ {
+ b.Id,
+ b.Path,
+ b.MediaStreams
+ })
+ .OrderBy(e => e.Id)
+ .WithPartitionProgress((partition) => _logger.LogInformation("Checked: {Count} - Moved: {Items} - Time: {Time}", partition * Limit, itemCount, sw.Elapsed))
+ .PartitionEagerAsync(Limit, cancellationToken)
+ .WithCancellation(cancellationToken)
+ .ConfigureAwait(false))
+ {
+ if (MoveSubtitleAndAttachmentFiles(result.Id, result.Path, result.MediaStreams, context))
{
- offset = records;
+ itemCount++;
}
-
- _logger.LogInformation("Checked: {Count} - Moved: {Items} - Time: {Time}", offset, itemCount, sw.Elapsed);
- } while (offset < records);
+ }
_logger.LogInformation("Moved files for {Count} items in {Time}", itemCount, sw.Elapsed);