diff options
| author | gnattu <gnattuoc@me.com> | 2025-02-04 15:38:25 +0800 |
|---|---|---|
| committer | gnattu <gnattuoc@me.com> | 2025-02-04 15:57:57 +0800 |
| commit | b0e853070ba368099fdc78d925d4d5675eb00d64 (patch) | |
| tree | 8f3de7e1fef3544f39a033fbfd88adc88f40f95b /Jellyfin.Server.Implementations | |
| parent | d376b5fbc7cf3ae7440a606a9e885d70605956bd (diff) | |
Don't use RETURNING clause with EFCore
The RETURNING clause helps with performance and is now default of EFCore. However, EFCore cannot automatically perform retry when the table was locked/busy. Disable it as a workaround for the locking issues of very huge databases.
Diffstat (limited to 'Jellyfin.Server.Implementations')
| -rw-r--r-- | Jellyfin.Server.Implementations/JellyfinDbContext.cs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/JellyfinDbContext.cs b/Jellyfin.Server.Implementations/JellyfinDbContext.cs index 34d9e3960..43ea2bd3c 100644 --- a/Jellyfin.Server.Implementations/JellyfinDbContext.cs +++ b/Jellyfin.Server.Implementations/JellyfinDbContext.cs @@ -4,6 +4,8 @@ using Jellyfin.Data.Entities; using Jellyfin.Data.Entities.Security; using Jellyfin.Data.Interfaces; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Implementations; @@ -271,4 +273,23 @@ public class JellyfinDbContext(DbContextOptions<JellyfinDbContext> options, ILog // Configuration for each entity is in its own class inside 'ModelConfiguration'. modelBuilder.ApplyConfigurationsFromAssembly(typeof(JellyfinDbContext).Assembly); } + + /// <inheritdoc/> + protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) + { + configurationBuilder.Conventions.Add(_ => new DoNotUseReturningClauseConvention()); + } + + private class DoNotUseReturningClauseConvention : IModelFinalizingConvention + { + public void ProcessModelFinalizing( + IConventionModelBuilder modelBuilder, + IConventionContext<IConventionModelBuilder> context) + { + foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) + { + entityType.UseSqlReturningClause(false); + } + } + } } |
