fix(perf): eliminate N+1 in AuditLogService by adding User navigation property

Added AppUser navigation property to AuditLog entity with EF Core
configuration (FK -> UserId, SetNull on delete). Replaced the sub-query
in AuditLogService ListAsync with a direct navigation property access,
enabling EF Core to generate a single LEFT JOIN instead of N sub-queries.

Migration: AddAuditLogUserRelation
This commit is contained in:
Arnaud Dartois committed 2026-07-17 19:24:07 +00:00
1 parent 015711e156
commit ec45fa3c87
6 files changed
+906 -1

No files matched your search

@@ -29,6 +29,12 @@ public class AuditLogConfiguration : IEntityTypeConfiguration<AuditLog>
builder.Property(al => al.Timestamp)
.HasDefaultValueSql("NOW()");
// Relationships
builder.HasOne(al => al.User)
.WithMany()
.HasForeignKey(al => al.UserId)
.OnDelete(DeleteBehavior.SetNull);
// Indexes
builder.HasIndex(al => al.Timestamp)
.IsDescending();