From 8637683ed70ee1935fd37e1b83a761322a4aba9f Mon Sep 17 00:00:00 2001 From: KhawarHabibKhan Date: Thu, 12 Mar 2026 23:09:40 +0500 Subject: [PATCH] Fix double-write in InterviewSessionRepository by removing redundant SaveChangesAsync --- .../InterviewSessionRepository.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/InterviewCoach.Mcp.InterviewData/InterviewSessionRepository.cs b/src/InterviewCoach.Mcp.InterviewData/InterviewSessionRepository.cs index ba53137..3f3426e 100644 --- a/src/InterviewCoach.Mcp.InterviewData/InterviewSessionRepository.cs +++ b/src/InterviewCoach.Mcp.InterviewData/InterviewSessionRepository.cs @@ -1,5 +1,3 @@ -using System.Text; - using Microsoft.EntityFrameworkCore; namespace InterviewCoach.Mcp.InterviewData; @@ -53,11 +51,13 @@ public async Task> GetAllInterviewSessionsAsync() record.ProceedWithoutJobDescription = interviewSession.ProceedWithoutJobDescription; record.UpdatedAt = DateTimeOffset.UtcNow; - var sb = new StringBuilder(); - sb.AppendLine(record.Transcript ?? string.Empty); - sb.AppendLine(); - sb.AppendLine(interviewSession.Transcript ?? string.Empty); - record.Transcript = sb.ToString(); + var existingTranscript = record.Transcript?.Trim(); + var newTranscript = interviewSession.Transcript?.Trim(); + record.Transcript = string.IsNullOrEmpty(existingTranscript) + ? newTranscript ?? string.Empty + : string.IsNullOrEmpty(newTranscript) + ? existingTranscript + : $"{existingTranscript}\n\n{newTranscript}"; await db.InterviewSessions.Where(r => r.Id == interviewSession.Id) .ExecuteUpdateAsync(r => r.SetProperty(p => p.ResumeLink, record.ResumeLink) @@ -69,7 +69,7 @@ await db.InterviewSessions.Where(r => r.Id == interviewSession.Id) .SetProperty(p => p.Transcript, record.Transcript) .SetProperty(p => p.UpdatedAt, record.UpdatedAt)); - await db.SaveChangesAsync(); + db.Entry(record).State = EntityState.Detached; return record; } @@ -87,7 +87,7 @@ await db.InterviewSessions.Where(r => r.Id == interviewSession.Id) await db.InterviewSessions.Where(p => p.Id == id) .ExecuteUpdateAsync(p => p.SetProperty(x => x.IsCompleted, true)); - await db.SaveChangesAsync(); + db.Entry(record).State = EntityState.Detached; return record; }