Skip to content

Commit 17654f7

Browse files
authored
Merge pull request #341 from lingarr-translate/prevent_duplicate_translation
prevent translation duplication
2 parents 050e470 + 75190e4 commit 17654f7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Lingarr.Server/Services/TranslationRequestService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,29 @@ public async Task<int> CreateRequest(TranslateAbleSubtitle translateAbleSubtitle
130130

131131
private async Task<int> EnqueueRequest(TranslationRequest translationRequest)
132132
{
133+
if (translationRequest.SubtitleToTranslate != null)
134+
{
135+
var existing = await _dbContext.TranslationRequests
136+
.Where(activeRequest =>
137+
activeRequest.SubtitleToTranslate == translationRequest.SubtitleToTranslate &&
138+
activeRequest.TargetLanguage == translationRequest.TargetLanguage &&
139+
new[]
140+
{
141+
TranslationStatus.Pending,
142+
TranslationStatus.InProgress
143+
}.Contains(activeRequest.Status))
144+
.Select(activeRequest => new { activeRequest.Id })
145+
.FirstOrDefaultAsync();
146+
147+
if (existing != null)
148+
{
149+
_logger.LogInformation(
150+
"Duplicate translation request skipped for '{Subtitle}' -> '{Language}' (existing id {Id}).",
151+
translationRequest.SubtitleToTranslate, translationRequest.TargetLanguage, existing.Id);
152+
return existing.Id;
153+
}
154+
}
155+
133156
// Create a new TranslationRequest to not keep ID and JobID
134157
var translationRequestCopy = new TranslationRequest
135158
{

0 commit comments

Comments
 (0)