From 1aa3341fc16081f7731cd3795334cb582bec15f3 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Fri, 19 Jan 2024 14:49:33 -0500 Subject: [PATCH] Restore duplicate removal --- Backend/Services/MergeService.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Backend/Services/MergeService.cs b/Backend/Services/MergeService.cs index 9f40ed2621..86e669a232 100644 --- a/Backend/Services/MergeService.cs +++ b/Backend/Services/MergeService.cs @@ -34,22 +34,27 @@ private async Task MergePrepParent(string projectId, MergeWords mergeWords parent.ProjectId = projectId; parent.History = new List(); - // Add child to history. foreach (var childSource in mergeWords.Children) { + // Add child to history. parent.History.Add(childSource.SrcWordId); + if (childSource.GetAudio) { - var child = await _wordRepo.GetWord(projectId, childSource.SrcWordId); - if (child is null) + // Add child's audio. + var child = await _wordRepo.GetWord(projectId, childSource.SrcWordId) + ?? throw new KeyNotFoundException($"Unable to locate word: ${childSource.SrcWordId}"); + child.Audio.ForEach(pro => { - throw new KeyNotFoundException($"Unable to locate word: ${childSource.SrcWordId}"); - } - parent.Audio.AddRange(child.Audio); + if (parent.Audio.All(p => p.FileName != pro.FileName)) + { + parent.Audio.Add(pro); + } + }); } } - // Remove duplicates. + // Remove history duplicates. parent.History = parent.History.Distinct().ToList(); return parent; }