mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-15 23:58:57 +00:00
Fixed Duplicate returns on grouping
Fixed UserDataKey not stored
This commit is contained in:
@@ -116,22 +116,23 @@ public sealed class BaseItemRepository(
|
||||
|
||||
using var context = dbProvider.CreateDbContext();
|
||||
var dbQuery = TranslateQuery(context.BaseItems.AsNoTracking(), context, filter);
|
||||
// .DistinctBy(e => e.Id);
|
||||
|
||||
var enableGroupByPresentationUniqueKey = EnableGroupByPresentationUniqueKey(filter);
|
||||
if (enableGroupByPresentationUniqueKey && filter.GroupBySeriesPresentationUniqueKey)
|
||||
{
|
||||
dbQuery = dbQuery.GroupBy(e => new { e.PresentationUniqueKey, e.SeriesPresentationUniqueKey }).SelectMany(e => e);
|
||||
dbQuery = dbQuery.GroupBy(e => new { e.PresentationUniqueKey, e.SeriesPresentationUniqueKey }).Select(e => e.First());
|
||||
}
|
||||
|
||||
if (enableGroupByPresentationUniqueKey)
|
||||
else if (enableGroupByPresentationUniqueKey)
|
||||
{
|
||||
dbQuery = dbQuery.GroupBy(e => e.PresentationUniqueKey).SelectMany(e => e);
|
||||
dbQuery = dbQuery.GroupBy(e => e.PresentationUniqueKey).Select(e => e.First());
|
||||
}
|
||||
|
||||
if (filter.GroupBySeriesPresentationUniqueKey)
|
||||
else if (filter.GroupBySeriesPresentationUniqueKey)
|
||||
{
|
||||
dbQuery = dbQuery.GroupBy(e => e.SeriesPresentationUniqueKey).SelectMany(e => e);
|
||||
dbQuery = dbQuery.GroupBy(e => e.SeriesPresentationUniqueKey).Select(e => e.First());
|
||||
}
|
||||
else
|
||||
{
|
||||
dbQuery = dbQuery.Distinct();
|
||||
}
|
||||
|
||||
dbQuery = ApplyOrder(dbQuery, filter);
|
||||
@@ -225,9 +226,15 @@ public sealed class BaseItemRepository(
|
||||
IQueryable<BaseItemEntity> dbQuery = context.BaseItems.AsNoTracking()
|
||||
.Include(e => e.TrailerTypes)
|
||||
.Include(e => e.Provider)
|
||||
.Include(e => e.Images)
|
||||
.Include(e => e.LockedFields);
|
||||
|
||||
if (filter.DtoOptions.EnableImages)
|
||||
{
|
||||
dbQuery = dbQuery.Include(e => e.Images);
|
||||
}
|
||||
|
||||
dbQuery = TranslateQuery(dbQuery, context, filter);
|
||||
dbQuery = dbQuery.Distinct();
|
||||
// .DistinctBy(e => e.Id);
|
||||
if (filter.EnableTotalRecordCount)
|
||||
{
|
||||
@@ -266,10 +273,34 @@ public sealed class BaseItemRepository(
|
||||
IQueryable<BaseItemEntity> dbQuery = context.BaseItems.AsNoTracking()
|
||||
.Include(e => e.TrailerTypes)
|
||||
.Include(e => e.Provider)
|
||||
.Include(e => e.Images)
|
||||
.Include(e => e.LockedFields);
|
||||
|
||||
if (filter.DtoOptions.EnableImages)
|
||||
{
|
||||
dbQuery = dbQuery.Include(e => e.Images);
|
||||
}
|
||||
|
||||
dbQuery = TranslateQuery(dbQuery, context, filter);
|
||||
dbQuery = ApplyOrder(dbQuery, filter);
|
||||
|
||||
var enableGroupByPresentationUniqueKey = EnableGroupByPresentationUniqueKey(filter);
|
||||
if (enableGroupByPresentationUniqueKey && filter.GroupBySeriesPresentationUniqueKey)
|
||||
{
|
||||
dbQuery = dbQuery.GroupBy(e => new { e.PresentationUniqueKey, e.SeriesPresentationUniqueKey }).Select(e => e.First());
|
||||
}
|
||||
else if (enableGroupByPresentationUniqueKey)
|
||||
{
|
||||
dbQuery = dbQuery.GroupBy(e => e.PresentationUniqueKey).Select(e => e.First());
|
||||
}
|
||||
else if (filter.GroupBySeriesPresentationUniqueKey)
|
||||
{
|
||||
dbQuery = dbQuery.GroupBy(e => e.SeriesPresentationUniqueKey).Select(e => e.First());
|
||||
}
|
||||
else
|
||||
{
|
||||
dbQuery = dbQuery.Distinct();
|
||||
}
|
||||
|
||||
if (filter.Limit.HasValue || filter.StartIndex.HasValue)
|
||||
{
|
||||
var offset = filter.StartIndex ?? 0;
|
||||
@@ -1330,7 +1361,7 @@ public sealed class BaseItemRepository(
|
||||
.Include(e => e.TrailerTypes)
|
||||
.Include(e => e.Provider)
|
||||
.Include(e => e.Images)
|
||||
.Include(e => e.LockedFields).AsNoTracking().FirstOrDefault(e => e.Id == id);
|
||||
.Include(e => e.LockedFields).AsNoTracking().AsSingleQuery().FirstOrDefault(e => e.Id == id);
|
||||
if (item is null)
|
||||
{
|
||||
return null;
|
||||
|
||||
1610
Jellyfin.Server.Implementations/Migrations/20241111131257_AddedCustomDataKey.Designer.cs
generated
Normal file
1610
Jellyfin.Server.Implementations/Migrations/20241111131257_AddedCustomDataKey.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddedCustomDataKey : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "CustomDataKey",
|
||||
table: "UserData",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "CustomDataKey",
|
||||
table: "UserData");
|
||||
}
|
||||
}
|
||||
}
|
||||
1610
Jellyfin.Server.Implementations/Migrations/20241111135439_AddedCustomDataKeyKey.Designer.cs
generated
Normal file
1610
Jellyfin.Server.Implementations/Migrations/20241111135439_AddedCustomDataKeyKey.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddedCustomDataKeyKey : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_UserData",
|
||||
table: "UserData");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "CustomDataKey",
|
||||
table: "UserData",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: string.Empty,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_UserData",
|
||||
table: "UserData",
|
||||
columns: new[] { "ItemId", "UserId", "CustomDataKey" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_UserData",
|
||||
table: "UserData");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "CustomDataKey",
|
||||
table: "UserData",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "TEXT");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_UserData",
|
||||
table: "UserData",
|
||||
columns: new[] { "ItemId", "UserId" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1276,6 +1276,9 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("CustomDataKey")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("AudioStreamIndex")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
@@ -1303,7 +1306,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
b.Property<int?>("SubtitleStreamIndex")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("ItemId", "UserId");
|
||||
b.HasKey("ItemId", "UserId", "CustomDataKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class UserDataConfiguration : IEntityTypeConfiguration<UserData>
|
||||
/// <inheritdoc/>
|
||||
public void Configure(EntityTypeBuilder<UserData> builder)
|
||||
{
|
||||
builder.HasKey(d => new { d.ItemId, d.UserId });
|
||||
builder.HasKey(d => new { d.ItemId, d.UserId, d.CustomDataKey });
|
||||
builder.HasIndex(d => new { d.ItemId, d.UserId, d.Played });
|
||||
builder.HasIndex(d => new { d.ItemId, d.UserId, d.PlaybackPositionTicks });
|
||||
builder.HasIndex(d => new { d.ItemId, d.UserId, d.IsFavorite });
|
||||
|
||||
Reference in New Issue
Block a user