diff options
| author | Niels van Velzen <nielsvanvelzen@users.noreply.github.com> | 2026-05-03 21:56:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-03 21:56:34 +0200 |
| commit | 6e22075a63432aae48859cf9c67fde158dc80d2e (patch) | |
| tree | c3a33238cc56857d8e3daa56db01f290118c9215 /Emby.Server.Implementations/ScheduledTasks | |
| parent | d9ced0d6399c82ddad9e983605bb0d828a608e63 (diff) | |
| parent | d68d0fa96267ad96eaa5a0ba37e072f59a71442a (diff) | |
Merge pull request #16062 from Shadowghost/perf-rebased
Query Performance Improvements
Diffstat (limited to 'Emby.Server.Implementations/ScheduledTasks')
| -rw-r--r-- | Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs | 16 | ||||
| -rw-r--r-- | Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionAndPlaylistPathsTask.cs | 139 |
2 files changed, 8 insertions, 147 deletions
diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs index 36708e2582..b2dc89be28 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs @@ -26,7 +26,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks; /// </summary> public partial class AudioNormalizationTask : IScheduledTask { - private readonly IItemRepository _itemRepository; + private readonly IItemPersistenceService _persistenceService; private readonly ILibraryManager _libraryManager; private readonly IMediaEncoder _mediaEncoder; private readonly IApplicationPaths _applicationPaths; @@ -38,21 +38,21 @@ public partial class AudioNormalizationTask : IScheduledTask /// <summary> /// Initializes a new instance of the <see cref="AudioNormalizationTask"/> class. /// </summary> - /// <param name="itemRepository">Instance of the <see cref="IItemRepository"/> interface.</param> + /// <param name="persistenceService">Instance of the <see cref="IItemPersistenceService"/> interface.</param> /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> /// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param> /// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param> /// <param name="localizationManager">Instance of the <see cref="ILocalizationManager"/> interface.</param> /// <param name="logger">Instance of the <see cref="ILogger{AudioNormalizationTask}"/> interface.</param> public AudioNormalizationTask( - IItemRepository itemRepository, + IItemPersistenceService persistenceService, ILibraryManager libraryManager, IMediaEncoder mediaEncoder, IApplicationPaths applicationPaths, ILocalizationManager localizationManager, ILogger<AudioNormalizationTask> logger) { - _itemRepository = itemRepository; + _persistenceService = persistenceService; _libraryManager = libraryManager; _mediaEncoder = mediaEncoder; _applicationPaths = applicationPaths; @@ -138,7 +138,7 @@ public partial class AudioNormalizationTask : IScheduledTask { if (toSaveDbItems.Count > 1) { - _itemRepository.SaveItems(toSaveDbItems, cancellationToken); + _persistenceService.SaveItems(toSaveDbItems, cancellationToken); toSaveDbItems.Clear(); } @@ -158,7 +158,7 @@ public partial class AudioNormalizationTask : IScheduledTask if (toSaveDbItems.Count > 1) { - _itemRepository.SaveItems(toSaveDbItems, cancellationToken); + _persistenceService.SaveItems(toSaveDbItems, cancellationToken); toSaveDbItems.Clear(); } @@ -183,7 +183,7 @@ public partial class AudioNormalizationTask : IScheduledTask { if (toSaveDbItems.Count > 1) { - _itemRepository.SaveItems(toSaveDbItems, cancellationToken); + _persistenceService.SaveItems(toSaveDbItems, cancellationToken); toSaveDbItems.Clear(); } @@ -200,7 +200,7 @@ public partial class AudioNormalizationTask : IScheduledTask if (toSaveDbItems.Count > 1) { - _itemRepository.SaveItems(toSaveDbItems, cancellationToken); + _persistenceService.SaveItems(toSaveDbItems, cancellationToken); } // Update progress diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionAndPlaylistPathsTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionAndPlaylistPathsTask.cs deleted file mode 100644 index 7f68f7701e..0000000000 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/CleanupCollectionAndPlaylistPathsTask.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Controller.Collections; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Movies; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Playlists; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Globalization; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Tasks; -using Microsoft.Extensions.Logging; - -namespace Emby.Server.Implementations.ScheduledTasks.Tasks; - -/// <summary> -/// Deletes path references from collections and playlists that no longer exists. -/// </summary> -public class CleanupCollectionAndPlaylistPathsTask : IScheduledTask -{ - private readonly ILocalizationManager _localization; - private readonly ICollectionManager _collectionManager; - private readonly IPlaylistManager _playlistManager; - private readonly ILogger<CleanupCollectionAndPlaylistPathsTask> _logger; - private readonly IProviderManager _providerManager; - - /// <summary> - /// Initializes a new instance of the <see cref="CleanupCollectionAndPlaylistPathsTask"/> class. - /// </summary> - /// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param> - /// <param name="collectionManager">Instance of the <see cref="ICollectionManager"/> interface.</param> - /// <param name="playlistManager">Instance of the <see cref="IPlaylistManager"/> interface.</param> - /// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param> - /// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param> - public CleanupCollectionAndPlaylistPathsTask( - ILocalizationManager localization, - ICollectionManager collectionManager, - IPlaylistManager playlistManager, - ILogger<CleanupCollectionAndPlaylistPathsTask> logger, - IProviderManager providerManager) - { - _localization = localization; - _collectionManager = collectionManager; - _playlistManager = playlistManager; - _logger = logger; - _providerManager = providerManager; - } - - /// <inheritdoc /> - public string Name => _localization.GetLocalizedString("TaskCleanCollectionsAndPlaylists"); - - /// <inheritdoc /> - public string Key => "CleanCollectionsAndPlaylists"; - - /// <inheritdoc /> - public string Description => _localization.GetLocalizedString("TaskCleanCollectionsAndPlaylistsDescription"); - - /// <inheritdoc /> - public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory"); - - /// <inheritdoc /> - public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken) - { - var collectionsFolder = await _collectionManager.GetCollectionsFolder(false).ConfigureAwait(false); - if (collectionsFolder is null) - { - _logger.LogDebug("There is no collections folder to be found"); - } - else - { - var collections = collectionsFolder.Children.OfType<BoxSet>().ToArray(); - _logger.LogDebug("Found {CollectionLength} boxsets", collections.Length); - - for (var index = 0; index < collections.Length; index++) - { - var collection = collections[index]; - _logger.LogDebug("Checking boxset {CollectionName}", collection.Name); - - await CleanupLinkedChildrenAsync(collection, cancellationToken).ConfigureAwait(false); - progress.Report(50D / collections.Length * (index + 1)); - } - } - - var playlistsFolder = _playlistManager.GetPlaylistsFolder(); - if (playlistsFolder is null) - { - _logger.LogDebug("There is no playlists folder to be found"); - return; - } - - var playlists = playlistsFolder.Children.OfType<Playlist>().ToArray(); - _logger.LogDebug("Found {PlaylistLength} playlists", playlists.Length); - - for (var index = 0; index < playlists.Length; index++) - { - var playlist = playlists[index]; - _logger.LogDebug("Checking playlist {PlaylistName}", playlist.Name); - - await CleanupLinkedChildrenAsync(playlist, cancellationToken).ConfigureAwait(false); - progress.Report(50D / playlists.Length * (index + 1)); - } - } - - private async Task CleanupLinkedChildrenAsync<T>(T folder, CancellationToken cancellationToken) - where T : Folder - { - List<LinkedChild>? itemsToRemove = null; - foreach (var linkedChild in folder.LinkedChildren) - { - var path = linkedChild.Path; - if (!File.Exists(path) && !Directory.Exists(path)) - { - _logger.LogInformation("Item in {FolderName} cannot be found at {ItemPath}", folder.Name, path); - (itemsToRemove ??= new List<LinkedChild>()).Add(linkedChild); - } - } - - if (itemsToRemove is not null) - { - _logger.LogDebug("Updating {FolderName}", folder.Name); - folder.LinkedChildren = folder.LinkedChildren.Except(itemsToRemove).ToArray(); - await _providerManager.SaveMetadataAsync(folder, ItemUpdateType.MetadataEdit).ConfigureAwait(false); - await folder.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); - } - } - - /// <inheritdoc /> - public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() - { - yield return new TaskTriggerInfo - { - Type = TaskTriggerInfoType.StartupTrigger, - }; - } -} |
