From 4d1a12b6b6f466e73de080d9a87e0cfa087ec53b Mon Sep 17 00:00:00 2001 From: Mik1ll <27949189+Mik1ll@users.noreply.github.com> Date: Fri, 31 Mar 2023 18:27:02 -0700 Subject: [PATCH] fix: AniDB languages not being updated properly * Added missing transaction * Ignore "none" result for language * Languages should still update if there are no results, they should be removed --- .../Commands/AniDB/CommandRequest_GetFile.cs | 24 ++++++++++--------- .../AniDB/UDP/Info/RequestGetFile.cs | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) 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);