diff --git a/Shoko.Server/Commands/AniDB/CommandRequest_GetFile.cs b/Shoko.Server/Commands/AniDB/CommandRequest_GetFile.cs index 620ce3fa4..2ea6239b7 100644 --- a/Shoko.Server/Commands/AniDB/CommandRequest_GetFile.cs +++ b/Shoko.Server/Commands/AniDB/CommandRequest_GetFile.cs @@ -138,34 +138,36 @@ protected override void Process() public void CreateLanguages(ResponseGetFile response) { using var session = DatabaseFactory.SessionFactory.OpenSession(); - if ((response?.AudioLanguages?.Count ?? 0) > - 0) //Only create relations if the origin of the data if from Raw (WebService/AniDB) + using var trans = session.BeginTransaction(); + // Only update languages if we got a response + if (response?.AudioLanguages is not null) { - // Delete old if changed - var fileLanguages = RepoFactory.CrossRef_Languages_AniDB_File.GetByFileID(response.FileID); - RepoFactory.CrossRef_Languages_AniDB_File.DeleteWithOpenTransaction(session, fileLanguages); + // Delete old + var toDelete = RepoFactory.CrossRef_Languages_AniDB_File.GetByFileID(response.FileID); + RepoFactory.CrossRef_Languages_AniDB_File.DeleteWithOpenTransaction(session, toDelete); + // Save new var toSave = response.AudioLanguages.Select(language => language.Trim().ToLower()) .Where(lang => lang.Length > 0) .Select(lang => new CrossRef_Languages_AniDB_File { LanguageName = lang, FileID = response.FileID }) .ToList(); - RepoFactory.CrossRef_Languages_AniDB_File.SaveWithOpenTransaction(session, toSave); } - if ((response?.SubtitleLanguages?.Count ?? 0) > 0) + if (response?.SubtitleLanguages is not null) { - // Delete old if changed - var fileLanguages = RepoFactory.CrossRef_Subtitles_AniDB_File.GetByFileID(response.FileID); - RepoFactory.CrossRef_Subtitles_AniDB_File.DeleteWithOpenTransaction(session, fileLanguages); + // Delete old + var toDelete = RepoFactory.CrossRef_Subtitles_AniDB_File.GetByFileID(response.FileID); + RepoFactory.CrossRef_Subtitles_AniDB_File.DeleteWithOpenTransaction(session, toDelete); + // Save new var toSave = response.SubtitleLanguages.Select(language => language.Trim().ToLower()) .Where(lang => lang.Length > 0) .Select(lang => new CrossRef_Subtitles_AniDB_File { LanguageName = lang, FileID = response.FileID }) .ToList(); - RepoFactory.CrossRef_Subtitles_AniDB_File.SaveWithOpenTransaction(session, toSave); } + trans.Commit(); } public void CreateEpisodes(string filename, ResponseGetFile response) diff --git a/Shoko.Server/Providers/AniDB/UDP/Info/RequestGetFile.cs b/Shoko.Server/Providers/AniDB/UDP/Info/RequestGetFile.cs index 181173850..8d9fcd336 100644 --- a/Shoko.Server/Providers/AniDB/UDP/Info/RequestGetFile.cs +++ b/Shoko.Server/Providers/AniDB/UDP/Info/RequestGetFile.cs @@ -222,10 +222,10 @@ protected override UDPResponse ParseResponse(UDPResponse lang != "none").ToList(); // sub languages - var slangs = parts[11].Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries).ToList(); + var slangs = parts[11].Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries).Where(lang => lang != "none").ToList(); // mylist var myList = ParseMyList(parts);