Skip to content

Commit faaa704

Browse files
committed
add migration for missing media_id column on translation_requests
1 parent 0941a69 commit faaa704

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

Lingarr.Core/LingarrVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Lingarr.Core;
55
public static class LingarrVersion
66
{
77
public const string Name = "Lingarr";
8-
public const string Number = "1.0.6";
8+
public const string Number = "1.0.7";
99

1010
public static async Task<VersionInfo> CheckForUpdates(object? lingarrApiService = null)
1111
{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentMigrator;
2+
3+
namespace Lingarr.Migrations.Migrations;
4+
5+
[Migration(6)]
6+
public class M0006_AddTranslationRequestMediaId : Migration
7+
{
8+
public override void Up()
9+
{
10+
if (!Schema.Table("translation_requests").Column("media_id").Exists())
11+
{
12+
Alter.Table("translation_requests")
13+
.AddColumn("media_id").AsInt32().Nullable();
14+
}
15+
}
16+
17+
public override void Down()
18+
{
19+
Delete.Column("media_id").FromTable("translation_requests");
20+
}
21+
}

Lingarr.Server/Services/MediaSubtitleProcessor.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private async Task<bool> ProcessSubtitles(
111111
return false;
112112
}
113113

114-
var languagesToTranslate = targetLanguages.Except(selected.AvailableLanguages);
114+
var languagesToTranslate = targetLanguages.Except(selected.AvailableLanguages).ToList();
115115
if (ignoreCaptions == "true")
116116
{
117117
var targetLanguagesWithCaptions = subtitles
@@ -130,24 +130,21 @@ private async Task<bool> ProcessSubtitles(
130130
}
131131
}
132132

133-
// Exclude languages that already have a pending, in-progress, or completed translation request
134-
// to prevent duplicate translations (see: https://github.com/lingarr-translate/lingarr/issues/312)
135133
var activeStatuses = new[]
136134
{
137135
TranslationStatus.Pending,
138136
TranslationStatus.InProgress,
139137
TranslationStatus.Completed
140138
};
141-
var existingLanguages = await _dbContext.TranslationRequests
142-
.Where(r => r.MediaId == _media.Id
143-
&& r.MediaType == _mediaType
144-
&& activeStatuses.Contains(r.Status))
145-
.Select(r => r.TargetLanguage)
139+
var existingTranslationRequests = await _dbContext.TranslationRequests
140+
.Where(translationRequest => translationRequest.MediaId == _media.Id
141+
&& translationRequest.MediaType == _mediaType
142+
&& activeStatuses.Contains(translationRequest.Status))
143+
.Select(translationRequest => translationRequest.TargetLanguage)
146144
.Distinct()
147145
.ToListAsync();
148146

149-
languagesToTranslate = languagesToTranslate.Except(existingLanguages);
150-
147+
languagesToTranslate = languagesToTranslate.Except(existingTranslationRequests).ToList();
151148
if (!languagesToTranslate.Any())
152149
{
153150
await UpdateHash();

0 commit comments

Comments
 (0)