From b09a41ad1f05664a6099734cb44e068f993a8e93 Mon Sep 17 00:00:00 2001
From: JPVenson <6794763+JPVenson@users.noreply.github.com>
Date: Wed, 9 Oct 2024 10:36:08 +0000
Subject: WIP porting new Repository structure
---
MediaBrowser.Controller/Library/IMediaSourceManager.cs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'MediaBrowser.Controller/Library/IMediaSourceManager.cs')
diff --git a/MediaBrowser.Controller/Library/IMediaSourceManager.cs b/MediaBrowser.Controller/Library/IMediaSourceManager.cs
index 44a1a85e3..5ed3a49c3 100644
--- a/MediaBrowser.Controller/Library/IMediaSourceManager.cs
+++ b/MediaBrowser.Controller/Library/IMediaSourceManager.cs
@@ -29,28 +29,28 @@ namespace MediaBrowser.Controller.Library
///
/// The item identifier.
/// IEnumerable<MediaStream>.
- List GetMediaStreams(Guid itemId);
+ IReadOnlyList GetMediaStreams(Guid itemId);
///
/// Gets the media streams.
///
/// The query.
/// IEnumerable<MediaStream>.
- List GetMediaStreams(MediaStreamQuery query);
+ IReadOnlyList GetMediaStreams(MediaStreamQuery query);
///
/// Gets the media attachments.
///
/// The item identifier.
/// IEnumerable<MediaAttachment>.
- List GetMediaAttachments(Guid itemId);
+ IReadOnlyList GetMediaAttachments(Guid itemId);
///
/// Gets the media attachments.
///
/// The query.
/// IEnumerable<MediaAttachment>.
- List GetMediaAttachments(MediaAttachmentQuery query);
+ IReadOnlyList GetMediaAttachments(MediaAttachmentQuery query);
///
/// Gets the playack media sources.
--
cgit v1.2.3
From 2014fa56b8ab0b0aec0b31ae0d2d9e2fce02ee53 Mon Sep 17 00:00:00 2001
From: JPVenson <6794763+JPVenson@users.noreply.github.com>
Date: Wed, 9 Oct 2024 10:41:54 +0000
Subject: Ported new Item Repository architecture
---
.../Library/MediaSourceManager.cs | 17 +++----
Jellyfin.Api/Controllers/InstantMixController.cs | 6 ++-
Jellyfin.Api/Helpers/StreamingHelpers.cs | 2 +-
.../Library/IMediaSourceManager.cs | 6 +--
.../Data/SqliteItemRepositoryTests.cs | 58 ++--------------------
5 files changed, 20 insertions(+), 69 deletions(-)
(limited to 'MediaBrowser.Controller/Library/IMediaSourceManager.cs')
diff --git a/Emby.Server.Implementations/Library/MediaSourceManager.cs b/Emby.Server.Implementations/Library/MediaSourceManager.cs
index a5a715721..3bf1a4cde 100644
--- a/Emby.Server.Implementations/Library/MediaSourceManager.cs
+++ b/Emby.Server.Implementations/Library/MediaSourceManager.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
+using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -164,7 +165,7 @@ namespace Emby.Server.Implementations.Library
});
}
- public async Task> GetPlaybackMediaSources(BaseItem item, User user, bool allowMediaProbe, bool enablePathSubstitution, CancellationToken cancellationToken)
+ public async Task> GetPlaybackMediaSources(BaseItem item, User user, bool allowMediaProbe, bool enablePathSubstitution, CancellationToken cancellationToken)
{
var mediaSources = GetStaticMediaSources(item, enablePathSubstitution, user);
@@ -217,7 +218,7 @@ namespace Emby.Server.Implementations.Library
list.Add(source);
}
- return SortMediaSources(list);
+ return SortMediaSources(list).ToImmutableList();
}
/// >
@@ -458,7 +459,7 @@ namespace Emby.Server.Implementations.Library
}
}
- private static List SortMediaSources(IEnumerable sources)
+ private static IEnumerable SortMediaSources(IEnumerable sources)
{
return sources.OrderBy(i =>
{
@@ -475,8 +476,7 @@ namespace Emby.Server.Implementations.Library
return stream?.Width ?? 0;
})
- .Where(i => i.Type != MediaSourceType.Placeholder)
- .ToList();
+ .Where(i => i.Type != MediaSourceType.Placeholder);
}
public async Task> OpenLiveStreamInternal(LiveStreamRequest request, CancellationToken cancellationToken)
@@ -811,7 +811,7 @@ namespace Emby.Server.Implementations.Library
return result.Item1;
}
- public async Task> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken)
+ public async Task> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken)
{
var stream = new MediaSourceInfo
{
@@ -834,10 +834,7 @@ namespace Emby.Server.Implementations.Library
await new LiveStreamHelper(_mediaEncoder, _logger, _appPaths)
.AddMediaInfoWithProbe(stream, false, false, cancellationToken).ConfigureAwait(false);
- return new List
- {
- stream
- };
+ return [stream];
}
public async Task CloseLiveStream(string id)
diff --git a/Jellyfin.Api/Controllers/InstantMixController.cs b/Jellyfin.Api/Controllers/InstantMixController.cs
index dcbacf1d7..e9dda19ca 100644
--- a/Jellyfin.Api/Controllers/InstantMixController.cs
+++ b/Jellyfin.Api/Controllers/InstantMixController.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
+using System.Linq;
using Jellyfin.Api.Extensions;
using Jellyfin.Api.Helpers;
using Jellyfin.Api.ModelBinders;
@@ -389,7 +391,7 @@ public class InstantMixController : BaseJellyfinApiController
return GetResult(items, user, limit, dtoOptions);
}
- private QueryResult GetResult(List items, User? user, int? limit, DtoOptions dtoOptions)
+ private QueryResult GetResult(IReadOnlyList items, User? user, int? limit, DtoOptions dtoOptions)
{
var list = items;
@@ -397,7 +399,7 @@ public class InstantMixController : BaseJellyfinApiController
if (limit.HasValue && limit < list.Count)
{
- list = list.GetRange(0, limit.Value);
+ list = list.Take(limit.Value).ToImmutableArray();
}
var returnList = _dtoService.GetBaseItemDtos(list, dtoOptions, user);
diff --git a/Jellyfin.Api/Helpers/StreamingHelpers.cs b/Jellyfin.Api/Helpers/StreamingHelpers.cs
index 3a5db2f3f..60b8804f7 100644
--- a/Jellyfin.Api/Helpers/StreamingHelpers.cs
+++ b/Jellyfin.Api/Helpers/StreamingHelpers.cs
@@ -132,7 +132,7 @@ public static class StreamingHelpers
mediaSource = string.IsNullOrEmpty(streamingRequest.MediaSourceId)
? mediaSources[0]
- : mediaSources.Find(i => string.Equals(i.Id, streamingRequest.MediaSourceId, StringComparison.Ordinal));
+ : mediaSources.FirstOrDefault(i => string.Equals(i.Id, streamingRequest.MediaSourceId, StringComparison.Ordinal));
if (mediaSource is null && Guid.Parse(streamingRequest.MediaSourceId).Equals(streamingRequest.Id))
{
diff --git a/MediaBrowser.Controller/Library/IMediaSourceManager.cs b/MediaBrowser.Controller/Library/IMediaSourceManager.cs
index 5ed3a49c3..729b385cf 100644
--- a/MediaBrowser.Controller/Library/IMediaSourceManager.cs
+++ b/MediaBrowser.Controller/Library/IMediaSourceManager.cs
@@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.Library
/// Option to enable path substitution.
/// CancellationToken to use for operation.
/// List of media sources wrapped in an awaitable task.
- Task> GetPlaybackMediaSources(BaseItem item, User user, bool allowMediaProbe, bool enablePathSubstitution, CancellationToken cancellationToken);
+ Task> GetPlaybackMediaSources(BaseItem item, User user, bool allowMediaProbe, bool enablePathSubstitution, CancellationToken cancellationToken);
///
/// Gets the static media sources.
@@ -70,7 +70,7 @@ namespace MediaBrowser.Controller.Library
/// Option to enable path substitution.
/// User to use for operation.
/// List of media sources.
- List GetStaticMediaSources(BaseItem item, bool enablePathSubstitution, User user = null);
+ IReadOnlyList GetStaticMediaSources(BaseItem item, bool enablePathSubstitution, User user = null);
///
/// Gets the static media source.
@@ -123,7 +123,7 @@ namespace MediaBrowser.Controller.Library
/// The .
/// The .
/// A task containing the 's for the recording.
- Task> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken);
+ Task> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken);
///
/// Closes the media source.
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs
index 0d2b488bc..1cf9e864d 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs
+++ b/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs
@@ -3,8 +3,10 @@ using System.Collections.Generic;
using AutoFixture;
using AutoFixture.AutoMoq;
using Emby.Server.Implementations.Data;
+using Jellyfin.Server.Implementations.Item;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Configuration;
using Moq;
@@ -18,7 +20,7 @@ namespace Jellyfin.Server.Implementations.Tests.Data
public const string MetaDataPath = "/meta/data/path";
private readonly IFixture _fixture;
- private readonly SqliteItemRepository _sqliteItemRepository;
+ private readonly BaseItemRepository _sqliteItemRepository;
public SqliteItemRepositoryTests()
{
@@ -40,7 +42,7 @@ namespace Jellyfin.Server.Implementations.Tests.Data
_fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true });
_fixture.Inject(appHost);
_fixture.Inject(config);
- _sqliteItemRepository = _fixture.Create();
+ _sqliteItemRepository = _fixture.Create();
}
public static TheoryData ItemImageInfoFromValueString_Valid_TestData()
@@ -101,7 +103,7 @@ namespace Jellyfin.Server.Implementations.Tests.Data
[MemberData(nameof(ItemImageInfoFromValueString_Valid_TestData))]
public void ItemImageInfoFromValueString_Valid_Success(string value, ItemImageInfo expected)
{
- var result = _sqliteItemRepository.ItemImageInfoFromValueString(value);
+ var result = _sqliteItemRepository.ItemImageInfoFromValueString(value)!;
Assert.Equal(expected.Path, result.Path);
Assert.Equal(expected.Type, result.Type);
Assert.Equal(expected.DateModified, result.DateModified);
@@ -243,56 +245,6 @@ namespace Jellyfin.Server.Implementations.Tests.Data
Assert.Equal(expected, _sqliteItemRepository.SerializeImages(value));
}
- public static TheoryData> DeserializeProviderIds_Valid_TestData()
- {
- var data = new TheoryData>();
-
- data.Add(
- "Imdb=tt0119567",
- new Dictionary()
- {
- { "Imdb", "tt0119567" },
- });
-
- data.Add(
- "Imdb=tt0119567|Tmdb=330|TmdbCollection=328",
- new Dictionary()
- {
- { "Imdb", "tt0119567" },
- { "Tmdb", "330" },
- { "TmdbCollection", "328" },
- });
-
- data.Add(
- "MusicBrainzAlbum=9d363e43-f24f-4b39-bc5a-7ef305c677c7|MusicBrainzReleaseGroup=63eba062-847c-3b73-8b0f-6baf27bba6fa|AudioDbArtist=111352|AudioDbAlbum=2116560|MusicBrainzAlbumArtist=20244d07-534f-4eff-b4d4-930878889970",
- new Dictionary()
- {
- { "MusicBrainzAlbum", "9d363e43-f24f-4b39-bc5a-7ef305c677c7" },
- { "MusicBrainzReleaseGroup", "63eba062-847c-3b73-8b0f-6baf27bba6fa" },
- { "AudioDbArtist", "111352" },
- { "AudioDbAlbum", "2116560" },
- { "MusicBrainzAlbumArtist", "20244d07-534f-4eff-b4d4-930878889970" },
- });
-
- return data;
- }
-
- [Theory]
- [MemberData(nameof(DeserializeProviderIds_Valid_TestData))]
- public void DeserializeProviderIds_Valid_Success(string value, Dictionary expected)
- {
- var result = new ProviderIdsExtensionsTestsObject();
- SqliteItemRepository.DeserializeProviderIds(value, result);
- Assert.Equal(expected, result.ProviderIds);
- }
-
- [Theory]
- [MemberData(nameof(DeserializeProviderIds_Valid_TestData))]
- public void SerializeProviderIds_Valid_Success(string expected, Dictionary values)
- {
- Assert.Equal(expected, SqliteItemRepository.SerializeProviderIds(values));
- }
-
private sealed class ProviderIdsExtensionsTestsObject : IHasProviderIds
{
public Dictionary ProviderIds { get; set; } = new Dictionary();
--
cgit v1.2.3