WIP BaseItem search refactoring

pull/12798/head
JPVenson 6 months ago
parent d3a3d9fce3
commit 6c819fe516

File diff suppressed because it is too large Load Diff

@ -161,4 +161,10 @@ public class BaseItem
public int? Height { get; set; }
public long? Size { get; set; }
public ICollection<People>? Peoples { get; set; }
public ICollection<UserData>? UserData { get; set; }
public ICollection<ItemValue>? ItemValues { get; set; }
}

@ -7,6 +7,7 @@ namespace Jellyfin.Data.Entities;
public class People
{
public Guid ItemId { get; set; }
public BaseItem Item { get; set; }
public required string Name { get; set; }
public string? Role { get; set; }

File diff suppressed because it is too large Load Diff

@ -1,26 +1,74 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Jellyfin.Data.Entities;
using MediaBrowser.Controller.Chapters;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using Microsoft.EntityFrameworkCore;
using BaseItemDto = MediaBrowser.Controller.Entities.BaseItem;
namespace Jellyfin.Server.Implementations.Item;
public class ChapterManager
/// <summary>
/// The Chapter manager.
/// </summary>
public class ChapterManager : IChapterManager
{
private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
private readonly IImageProcessor _imageProcessor;
public ChapterManager(IDbContextFactory<JellyfinDbContext> dbProvider)
/// <summary>
/// Initializes a new instance of the <see cref="ChapterManager"/> class.
/// </summary>
/// <param name="dbProvider">The EFCore provider.</param>
/// <param name="imageProcessor">The Image Processor.</param>
public ChapterManager(IDbContextFactory<JellyfinDbContext> dbProvider, IImageProcessor imageProcessor)
{
_dbProvider = dbProvider;
_imageProcessor = imageProcessor;
}
public IReadOnlyList<ChapterInfo> GetChapters(BaseItemDto baseItemDto)
/// <inheritdoc cref="IChapterManager"/>
public ChapterInfo? GetChapter(BaseItemDto baseItem, int index)
{
using var context = _dbProvider.CreateDbContext();
return context.Chapters.Where(e => e.ItemId.Equals(baseItemDto.Id)).Select(Map).ToList();
var chapter = context.Chapters.FirstOrDefault(e => e.ItemId.Equals(baseItem.Id) && e.ChapterIndex == index);
if (chapter is not null)
{
return Map(chapter, baseItem);
}
return null;
}
/// <inheritdoc cref="IChapterManager"/>
public IReadOnlyList<ChapterInfo> GetChapters(BaseItemDto baseItem)
{
using var context = _dbProvider.CreateDbContext();
return context.Chapters.Where(e => e.ItemId.Equals(baseItem.Id))
.ToList()
.Select(e => Map(e, baseItem))
.ToImmutableArray();
}
/// <inheritdoc cref="IChapterManager"/>
public void SaveChapters(Guid itemId, IReadOnlyList<ChapterInfo> chapters)
{
using var context = _dbProvider.CreateDbContext();
using (var transaction = context.Database.BeginTransaction())
{
context.Chapters.Where(e => e.ItemId.Equals(itemId)).ExecuteDelete();
for (var i = 0; i < chapters.Count; i++)
{
var chapter = chapters[i];
context.Chapters.Add(Map(chapter, i, itemId));
}
context.SaveChanges();
transaction.Commit();
}
}
private Chapter Map(ChapterInfo chapterInfo, int index, Guid itemId)

@ -10,9 +10,7 @@ namespace MediaBrowser.Providers.Chapters
{
public class ChapterManager : IChapterManager
{
private readonly IItemRepository _itemRepo;
public ChapterManager(IItemRepository itemRepo)
public ChapterManager(IDbContextFactory<JellyfinDbContext> dbProvider)
{
_itemRepo = itemRepo;
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Chapters
@ -15,5 +16,20 @@ namespace MediaBrowser.Controller.Chapters
/// <param name="itemId">The item.</param>
/// <param name="chapters">The set of chapters.</param>
void SaveChapters(Guid itemId, IReadOnlyList<ChapterInfo> chapters);
/// <summary>
/// Gets all chapters associated with the baseItem.
/// </summary>
/// <param name="baseItem">The baseitem.</param>
/// <returns>A readonly list of chapter instances.</returns>
IReadOnlyList<ChapterInfo> GetChapters(BaseItemDto baseItem);
/// <summary>
/// Gets a single chapter of a BaseItem on a specific index.
/// </summary>
/// <param name="baseItem">The baseitem.</param>
/// <param name="index">The index of that chapter.</param>
/// <returns>A chapter instance.</returns>
ChapterInfo? GetChapter(BaseItemDto baseItem, int index);
}
}

@ -39,28 +39,6 @@ namespace MediaBrowser.Controller.Persistence
/// <returns>BaseItem.</returns>
BaseItem RetrieveItem(Guid id);
/// <summary>
/// Gets chapters for an item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>The list of chapter info.</returns>
List<ChapterInfo> GetChapters(BaseItem item);
/// <summary>
/// Gets a single chapter for an item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="index">The chapter index.</param>
/// <returns>The chapter info at the specified index.</returns>
ChapterInfo GetChapter(BaseItem item, int index);
/// <summary>
/// Saves the chapters.
/// </summary>
/// <param name="id">The item id.</param>
/// <param name="chapters">The list of chapters to save.</param>
void SaveChapters(Guid id, IReadOnlyList<ChapterInfo> chapters);
/// <summary>
/// Gets the media streams.
/// </summary>

@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="PlaylistsNET" />
<PackageReference Include="z440.atl.core"/>
<PackageReference Include="z440.atl.core" />
<PackageReference Include="TMDbLib" />
</ItemGroup>

Loading…
Cancel
Save