From a6b4d124d71c0bbb9dff5f226e65875e03384ab4 Mon Sep 17 00:00:00 2001 From: JPVenson Date: Sat, 1 Mar 2025 14:16:02 +0000 Subject: [PATCH] Replicated changes made from #13492 --- .../IJellyfinDatabaseProvider.cs | 6 ++++++ .../JellyfinDbContext.cs | 7 +++++++ .../DoNotUseReturningClauseConvention.cs | 20 +++++++++++++++++++ .../SqliteDatabaseProvider.cs | 6 ++++++ 4 files changed, 39 insertions(+) create mode 100644 src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/DoNotUseReturningClauseConvention.cs diff --git a/src/Jellyfin.Database/Jellyfin.Database.Implementations/IJellyfinDatabaseProvider.cs b/src/Jellyfin.Database/Jellyfin.Database.Implementations/IJellyfinDatabaseProvider.cs index b27a88971d..cc96792e64 100644 --- a/src/Jellyfin.Database/Jellyfin.Database.Implementations/IJellyfinDatabaseProvider.cs +++ b/src/Jellyfin.Database/Jellyfin.Database.Implementations/IJellyfinDatabaseProvider.cs @@ -27,6 +27,12 @@ public interface IJellyfinDatabaseProvider /// The ModelBuilder from EFCore. void OnModelCreating(ModelBuilder modelBuilder); + /// + /// Will be invoked when EFCore wants to configure its model. + /// + /// The ModelConfigurationBuilder from EFCore. + void ConfigureConventions(ModelConfigurationBuilder configurationBuilder); + /// /// If supported this should run any periodic maintaince tasks. /// diff --git a/src/Jellyfin.Database/Jellyfin.Database.Implementations/JellyfinDbContext.cs b/src/Jellyfin.Database/Jellyfin.Database.Implementations/JellyfinDbContext.cs index a0a0f2d0ee..c65006c7d8 100644 --- a/src/Jellyfin.Database/Jellyfin.Database.Implementations/JellyfinDbContext.cs +++ b/src/Jellyfin.Database/Jellyfin.Database.Implementations/JellyfinDbContext.cs @@ -272,4 +272,11 @@ public class JellyfinDbContext(DbContextOptions options, ILog // Configuration for each entity is in its own class inside 'ModelConfiguration'. modelBuilder.ApplyConfigurationsFromAssembly(typeof(JellyfinDbContext).Assembly); } + + /// + protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) + { + jellyfinDatabaseProvider.ConfigureConventions(configurationBuilder); + base.ConfigureConventions(configurationBuilder); + } } diff --git a/src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/DoNotUseReturningClauseConvention.cs b/src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/DoNotUseReturningClauseConvention.cs new file mode 100644 index 0000000000..1ce2420e43 --- /dev/null +++ b/src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/DoNotUseReturningClauseConvention.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; + +namespace Jellyfin.Database.Providers.SqLite; + +internal class DoNotUseReturningClauseConvention : IModelFinalizingConvention +{ + /// + public void ProcessModelFinalizing( + IConventionModelBuilder modelBuilder, + IConventionContext context) + { + foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) + { + entityType.UseSqlReturningClause(false); + } + } +} diff --git a/src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/SqliteDatabaseProvider.cs b/src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/SqliteDatabaseProvider.cs index f7fde4989e..2364186b12 100644 --- a/src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/SqliteDatabaseProvider.cs +++ b/src/Jellyfin.Database/Jellyfin.Database.Providers.SqLite/SqliteDatabaseProvider.cs @@ -78,4 +78,10 @@ public sealed class SqliteDatabaseProvider : IJellyfinDatabaseProvider SqliteConnection.ClearAllPools(); } + + /// + public void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) + { + configurationBuilder.Conventions.Add(_ => new DoNotUseReturningClauseConvention()); + } }