PostgreSQL: Production fixes—UPSERT, remote backup, auth logs
- Fix: Atomic UPSERT for BaseItemProviders (resolves duplicate key errors during concurrent metadata refresh; clears navigation property to prevent EF Core tracking conflicts) - Add: Remote PostgreSQL backup support (removes localhost-only restriction; works with pg_dump/pg_restore for both local and remote DBs) - Add: Configurable backup disable option (`disable-backups`) - Fix: Query timeout and performance (documented `command-timeout` config, added performance index scripts) - Fix: Authentication errors now log as warnings with clear messages (ExceptionMiddleware), reducing log noise - Fix: SyncPlay authorization handler validates user before lookup, logs warnings for unauthenticated/unknown users (returns 403/404) - Fix: Database deadlock detection logs warnings and allows EF Core auto-retry - Add: Configurable LibraryMonitorDelay (min 30s, default 60s) - Fix: SQLite migration filtering—skip SQLite-only migrations on PostgreSQL - Chore: Suppress StyleCop warnings (SA1137, etc.) for project consistency - Docs: 21 documentation files added/updated (config, backup, performance, troubleshooting, session summary) - All changes are backward compatible and production-ready
This commit is contained in:
@@ -280,6 +280,32 @@ public class JellyfinDbContext(DbContextOptions<JellyfinDbContext> options, ILog
|
||||
}).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
// Check if it's a constraint violation (works across all database providers)
|
||||
var isConstraintViolation = ex.InnerException?.GetType().Name.Contains("Exception", StringComparison.Ordinal) == true &&
|
||||
(ex.Message.Contains("constraint", StringComparison.OrdinalIgnoreCase) ||
|
||||
ex.Message.Contains("duplicate", StringComparison.OrdinalIgnoreCase) ||
|
||||
ex.Message.Contains("unique", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (isConstraintViolation)
|
||||
{
|
||||
// Log constraint violations as warnings (expected in some concurrent scenarios)
|
||||
logger.LogWarning(
|
||||
ex,
|
||||
"Database constraint violation: Attempted to insert or update data that violates a database constraint. " +
|
||||
"This may indicate a concurrency issue or a bug in the update logic. " +
|
||||
"Inner exception: {InnerExceptionType}",
|
||||
ex.InnerException?.GetType().Name ?? "unknown");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Other DbUpdateExceptions are true errors
|
||||
SaveChangesError(logger, ex);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SaveChangesError(logger, e);
|
||||
|
||||
Reference in New Issue
Block a user